The focus of OSM is providing data - not so much providing data access APIs. It is possible that you could do something with Overpass that gets you halfway there, but if you need to make these kinds of queries often, it would be a good idea to

download the full "planet file" with all OSM data,

import it into a PostGIS database using e.g. osm2pgsql with a modified "style file" that essentially tells osm2pgsql you're only interested in place names or settlements (alternatively: use osmium-tool to filter the planet file for place names or settlements, then use plain osm2pgsql to import the resulting file)

use a PostGIS query to find the nearest place to a given pair of coordinates

Since you're only interested in a fraction of OSM data, you shouldn't need too much disk space or memory for this, and you'll be able to make fast queries.