What determines the psi stat in Xcom 2?

You start with 50 when the Psi Operative gets his first ability and get a random amount (min 4, max 12) every time he is promoted. The Psi Operative is promoted every time he learns a new ability, until he reaches the maximum level (level 7, Magus). The unmodified stat is capped at 100, which means a Magus has 74-100 Psi stat, but the expected value is much closer to 100 than 74.

The stat gains for every promotion are defined in one of the .ini files (DefaultClassData.ini). Will grows the same way as Psi Offense (+4-12 per promotion with 100 cap) but you can also get extra will when you bring a shaken soldier for a mission.