The answer to why browsers allow connections to 127.0.0.1 from external sites is probably something like "legacy reasons".
You can't always depend on that. eg. when you're on public/enterprise wifi that intercepts DNS requests.
Let me know how that works with DNS over HTTP
Custom hostnames are such a better solution, but for some reason developers don't use them.
Localhost is just another site. If you want to make it secure, make it secure.
You realize that anybody on your coffeeshop wifi can also connect to your localhost server, don't you? Just because a server is running on your laptop doesn't mean it's not a server, running on the internet.
Also at least by convention, localhost is only accessible via the loopback interface. This allows it to be accessible even if there is no physical network to connect to, but also means that it is only accessible on the same physical/virtual computer that it is running.
To let other people in the coffee shop access your software you would need to connect to a public or private interface.