Any CPs that a Battle-forged army has remaining after purchasing Detachments can be spent to utilise Stratagems - each of which represents a strategic or tactical asset available to your army.
To include a particular Detachment in your army, you must first spend a number of CPs equal to that Detachment’s Command Cost. If you do not have enough CPs for a specific Detachment, you cannot include it in your army. Then, you simply organise some or all of the units in your army so that they fit within the restrictions and limitations detailed for that Detachment.
So, you spend points on all of the units in your army, then buy detachments and while buying detachments fill them with the units you spent points on.
Only after buying all of your detachments can you spend
CP on stratagems. Therefore, you can only spend
CP on stratagems after buying all of the units in your army.