The commander can be attached to a unit and some must be e.g. beserkers. The general still has a 12" radius of command measured from the centre front of the unit. Other commanders can only enhance cohesion when attached to a unit.
Commanders can leave a unit when they wish unless the unit is subject to compulsory moves.
When attached to a unit there is a chance that the commander can become a casualty from shooting or combat when the unit suffers unsaved hits.
If a commander is not in a unit he cannot be attacked.
If he is in the path of a charge or pursuit, move him aside.
The only exception that I know of is the later Persian Great king if he is in a chariot.
The Persian Great King remains an exception. Historically he frequently rode a heavy chariot so the army-list allows it. There are no heavy chariot units for him to join and he cannot join any other unit. See page 16 of the classical lists.