In the most frequent case (that is using EPP without specific extension), a transfer of domain name is made without any change to its current technical configuration. So the nameservers can be changed just before the transfer is started or just after it is completed but not during it.
You can not change anything on the domain name while the transfer is pending because the domain will be in pending Transfer
EPP status, and no update on a domain name is allowed when it is under a "pending" status.
The former registrar can do nothing even if it wanted to, as soon as the transfer is started, as this under control of the registry. This is not an ICANN policy, this is a technical rule described in the EPP RFCs (see STD69 at https://www.rfc-editor.org/info/std69)
In gTLDs, the transfer can typically last up to 5 days, but this is for administrative reasons, not technical ones. You can speed it up by explicitely allowing it at the current sponsoring registrar (for those allowing their customers to have this option).
Note that in some TLDs you can specify, at the moment you do the transfer, the new nameservers to use, but this will be done after the transfer is finished also. You can get the same behaviour with any competent registrar for any TLD to which you would have decided to transfer the domain to: it can record both your order to do the transfer and the new nameservers you would like, so that it can, as soon as the transfer finishes, put the new nameservers automatically for you.