Your accommodation is honestly the fastest directory you have. Hotel front desks, hosts and landlords answer this question weekly and know which nearby clinic treats foreigners well and which pharmacy stays open late, so ask them first, even by message at midnight.
Beyond that, standard map apps work well in most countries for finding hospitals and pharmacies with hours and reviews, and searching for a 24-hour pharmacy in the local language gets better results than English in many places. Many countries also run an on-duty pharmacy rotation, where one pharmacy per neighborhood stays open overnight, and the list is posted on every pharmacy's door or on a municipal website. Big cities usually have international clinics that cater specifically to foreigners.
Two more resources worth knowing: your travel insurer's app or hotline typically has a directory of approved facilities and can direct you somewhere they will pay directly, and most embassies publish a list of English-speaking doctors and hospitals on their website. Save the nearest hospital's location in your phone on your first day in any new city; it costs one minute and pays off when you least want to be searching.