Extranonce2 is generated by the miner performing the work. When a miner runs out of nonces in the block header, they can increment Extranonce2 in the coinbase transaction to be able to give themselves a much larger search space for a valid PoW for the difficulty that they are mining at.
The pool has to provide the size of Extranonce2 because Extranonce2 is not an actual field in the coinbase but rather part of the variable length arbitrary data that a miner can include in the coinbase transaction. So the pool specifies the size so that the miner knows how much space they have to work with for Extranonce2.