How can I rescue dorfs trapped in semi-molten rock?

Solution 1:

Forget about ramps; have them build an up stair and then down/up staira until they can get out. It takes the same number of raw stones to craft, but is easier to use than a ramp.

The wiki has more, but essentially, your problem is that for ramps to work, they also need walls (which it sounds like you have not built).

Solution 2:

If you dump stones on their heads, they might die. Just letting you know. However, if you have enough space for them to stand to the side, that might work.