What is the solution then? The problem is probably more that there aren’t enough pharmacists to run 24/7 pharmacies within walking distance of everyone in a city.
Also even cities with great public transport infrastructure have a spotty night schedule or don’t even have one at all. Like even in Tokyo you can get stranded if you miss the last bus/train and then you have to wait till the morning or call a taxi
This situation would have happened in any city , walkable or not, unless you live near a pharmacy that is open at night.