Is your raised bed sitting on ground? Can the tomato roots grow down into it? If so, then it doesn't really matter how deep the bed is. But yes, definitely too many plants in it. TWO
tomato plants would go in a 4x4. If you have another place to put them, you can carefully dig the others out, taking a root ball and the soil around it and replanting right away. When you replant, bury them deeper than they were before. But I can't imagine what kind of yard you would have where you have room for 30 tomato plants. You would need about 250 sq ft of garden space.
Your 31 plants will just all be competing with each other for sun, water, nutrients, and the plants all growing on top of each other cut down air circulation and transmit pests and diseases. They will be weak and stunted and then will be vulnerable to what ever pests and diseases come along.
Tomatoes do best with some kind of stake/cage/ trellis situation. You didn't say where you are, but at least in any kind of humid climate, tomato leaves that touch the ground or get dirt splashed up onto them, are very prone to fungal diseases. And if a tomato fruit touches the ground, it will rot. I grow mine in cages and take all the bottom branches/leaves off, so that nothing touches the ground.
Everybody loves to grow tomatoes (and there is nothing like your own garden tomatoes!
), but for many of us, with humid climates and/or short growing season, they aren't actually the easiest thing to grow. Obviously it can be done, but it takes a bit of care.