Incidentally I had this exact same discussion with my roommate a month ago. I rented that episode from the library and neither of us knew why they didn’t fall through the floor even though walls didn’t have a problem for them.
Maybe that’s where Mark Twain got the idea.
If it was Voyager, the reason would involve either an anomoly, nanoprobes, or Neelix’s cooking.
Or changing the frequency of something.
Seriously, looking for any rational explanation for anything in Star Trek is an exercise in futility.
Ah come on, the only uniquely Voyageresque solution is Neelix’s cuisine.
^ :dubious: ^
Hell, I used to wonder the same thing about Caspar.
I’ll take a swing.
On Federation starships, the apparently earth-normal gravity is created deck-by-deck by gravitic plating (which is likewise present in places like Jeffries tubes). The substance of those plates and the pseudo-gravity they create was very mildly repulsive to Geordi and Larren in their phased state; thus they could pass through walls & doors (which lack gravitic plating) but not the floor.
Of course, that doesn’t explain how the Romulan officer was able to sit in a chair.
Hmm…
Okay, the whole episode was a holodeck program written by Tom Paris.
Except Caspar is explicitly supernatural, and thus, by definition, not reliably subject to natural law.
This is Star Trek, so take a look at post 14.
I don’t care, “Caspar” is one of the best answers to a Trek question I’ve seen. 
It’s because of Shimmer. It’s a floor wax, a dessert topping, and provides a metastable ion matrix allowing it to impede phased entities.
- Also a member of the NitPicker’s Guild