"Obsolete" can mean three things:
1) You can no longer build the unit
2) You can still build the unit, but you can also build other units that perform the same task more efficiently.
3) Your existing units are no longer effective in their former role owing to enemy technology.
Case (1) happens when you can build all of the new units the old one could possibly upgrade to. For example, Archers can become Longbowmen or Crossbowmen. When you can build both Longbowmen and Crossbowmen, you can no longer build Archers. Because some units require resources, this is assessed on a city-by-city basis. For example, even if you have the technology for both Crossbowmen and Longbowmen, you will still be able to build Archers in a city not connected to Iron. This is often a source of confusion, so double check with the Civilopedia on what units can upgrade to and what resources those upgrades require.
Case (2) is a function of the various strengths and skills of particular units. For example, Spearmen are effectively obsolete once you have Elephants. Even though you can still build Spearmen, an Elephant is just more effective at almost any task for which you would want a Spearman. Consult the Civilopedia for the details.
Case (3) is also function of unit strengths and roles. Praetorians, for example, are strictly obsoleted by Macemen and Crossbowmen, as they are the inferior combatant on almost any terrain. However, Praetorians are also partially obsoleted by enemy Longbowmen. Even though a Praetorian is superior on open ground, they are most useful for attacking cities, where a Longbowman enjoys significant defensive bonuses. Once again, studying the Civilopedia for specific details after learning the general mechanics is your best bet at this stage.