robots.txt is a way of leaving the door unlocked but kindly asking bots to stay outside.
Which in a law-abiding society should be enough. It's also how we do things in the real world in many cases - i.e. here you can just write on your mailbox "no ads" and companies have to respect that.
Even when we do actually put physical locks on things they are mostly there to show that someone breaking in did so intentionally and not at all designed to prevent motivated attackers.
You might be interested to know that entering an unlocked door into a space you do not have permission to be in is still illegal.