For BFME1, the gained experience is the amount of resources you spend to recruit the unit. The exception is the orc warrior which is build for free but still has a internal cost of 100 so it levels up the orc pit. I guess it is handled in a similar way in BFME2.
I don't know how you could separate the cost from the gained experience other than making a unit completely free.
- OneV likes this