Why do hotels have different building codes? If the room I'm sleeping in catches fire and collapses, no legal arrangement with the landlord is going to save me.
All types of buildings have different building codes.
Apartment buildings may have different codes depending on their height (you can't build a 10 story wooden building for instance), there's codes which regulate exits, access, max occupancy, etc... Single family homes have different code to follow because the expectation is that only 1 family will be living in it, versus an office tower or hotel with thousands...
A relevant example - not every basement is suitable as a living suite, but many are rented out anyway, which is against the law (there are certain codes which much be followed to ensure a rental suite is legal). This would apply to AirBnB as well. Traditional bed and breakfast places have rules to follow as well, business regulations, building code, etc...
Because the occupants of a hotel are temporary and not familiar with the building, the building operator takes on more responsibility for their well-being. Partly this is in better fire protection, partly this in things like having those exit plans on the door and having a designated fire safety director.
If the room I'm sleeping in catches fire and collapses, no legal arrangement with the landlord is going to save me.
Since you mention it, I suspect that an "official" hotel room has to be built and maintained to a much higher standard than someone's house or apartment. Width of exits, sprinkler systems, etc.