End of life buys are a common to ensure stocks are adequate.
Not so much in this case, most were acquired through Lend Lease, certainly the RNZAF examples were. The problem was that no one had any real certainty of when the war might come to a satisfactory conclusion, nor when exactly the P-40 might be replaced; it was still of considerable use until the war's end in the island hopping campaigns in the Pacific. As for replacing it, the RNZAF bought Corsairs and Mustangs, the former were used almost exclusively for attack and the latter not arriving until the very end of the war, so the P-40 soldiered on until the end of the war. The RAAF was building Mustangs under licence, but throughout the war until its end, the P-40 remained its most numerous and important fighter.