The basic idea in Spelunky-style dungeons is having a number of prefabricated room templates stored in some manner. Imagine for example a 11x11 cell grid. At its simplest, you would set each grid cell either to zero to indicate an empty tile, or to one to indicate a wall tile. When a prefab piece is used to build a dungeon, the constructor would loop through every cell and set a wall pieces at designated spots. The steps inside the room would depend on your tile sprite sizes. If it were 32x32 pixels, the constructor loop would step the creation location 32 pixels every time it jumps to next grid cell.
To construct an entire dungeon of these prefab pieces, you'd first initialize another grid. Then you'd fill it with IDs of the prefab pieces, either completely randomly or according to some algorithm. After that loop through the grid, fetch the prefab piece data and construct the dungeon piece by piece as explained above. Important thing is to construct your prefab pieces according to some guideline so they all fit together at the edges.
One method I've used for this is maze generation algorithms. It would first create a maze on for example a 8x8 grid, and then I would pick suitable prefab room based on where the exits on each maze cell lie.