It has to do with pressure, which is what would cause a nail to hurt your skin. If you lightly touch a nail, it does not hurt. Apply more pressure and it hurts. Pressure is force over area. P = F / A. The smaller the amount of area, the greater the pressure. Stepping on a tack really hurts because you have a large force over a tiny area (the tip of the tack). If you step on a round stone you still feel the pressure, but it is a lot less, since the surface area against your foot is much bigger.
A bed with a single nail would be very painful and hurt you. Let's say you weigh 100 lbs and that nail tip is .01 square inches. The pressure is 100 / .01 = 10,000 pounds per square inch (PSI), which is huge. Now imagine a bed of nails with 1000 nails in them. For the same 100 lb person the amount of surface area is lot greater for the nails. Instead of .01 sq inch, it is 1000 times that, or a sum total of 10 sq inch of nail distributed evenly against their body. The pressure becomes 100/10 = 10 PSI, which is a lot less and would allow a person to lay on it without getting hurt at all.
A more simple explanation is that the force is spread out more with more nails, but now you understand it better I hope.