NPCs have three location settings that control where they spend their time:
During the simulation, NPCs move between these locations on their own. Building owners always stay at their home location. Other NPCs drift between home, workplace, and their social haunts depending on the time of day.
You'll find NPCs in different buildings depending on when you visit. Check the building tooltips on the settlement map to see who's where right now.
You can edit any NPC's routine from the Atlas NPCs tab:

NPCs can travel to other settlements on a configurable schedule. Open an NPC in the Atlas and look for the Travel Schedule section to set up cross-settlement trips.
The calendar UI lets you:
When an NPC is traveling, they leave their home settlement and can be found at their destination. They return home at the end of the trip.
This is useful for creating traveling merchants, wandering scholars, or NPCs with responsibilities in multiple settlements.