To get a unit to switch back to its primary weapon, select the unit and right click (as opposed to Alt+right click) on whatever you wish to attack. For example, if you have a unit of Iphikratous Hoplites engaged with a unit of cavalry and they happen to be using swords, simply select them and right click on the cavalry unit they are already engaged with. This will cause them to swap back to their spears.