Some locations lock the doors.
In the ghetto? Oops, I don’t think I’ve ever seen a Starbucks in a poor neighborhood.
I doubt that the restrooms are locked.
And some locations post a sign "Restroom for Customers Only." However, they may let in anyone who first asks them.
I have no problem with buying a very small item (e.g. a cookie) to elevate myself to "customer" status if need be.