You can wear sunscreen in a tanning bed but it won't do your skin any good since sunscreen is only effective at blocking natural UV rays from the natural sunlight.
The artificial UV rays that come from the tanning bed cannot be blocked properly by the sunscreen so using sunscreen in a tanning bed won't do any good.
The UV rays from a tanning bed are stronger and more dangerous than the natural sunlight UV rays so you should limit your time in a tanning bed and you must also wear sunglasses in the tanning bed to prevent yourself from becoming blind.
Just keeping your eyes closed is not enough to block the dangerous UV rays from the tanning bed.