While the sights of the capital city of San José may appeal to human visitors, they aren't appreciated by sloths, so you probably won't simply bump into one in the city.
The best way to see a sloth is to venture into the moisture-dense rainforests in areas like La Fortuna, Tortuguero, Monteverde, Puerto Viejo, and the Manuel Antonio National Park.
Whether or not you see a sloth also depends on when you visit. Although you can spot them year-round, they are largely nocturnal creatures and prefer the rainier seasons.
Even if you're prepped for a Costa Rican adventure with all the knowledge you need, you may still not see a sloth. It's best to hire a guide who can spot them with a telescope.