When an AirPlay pairing code (4-digit PIN) is displayed on the screen for the destination device, then that should be copied to the sending device that is asking for the code.
AirPlay codes should stay valid (per device pair) until something in the setup changes (like a reset), when set to “first time only”. Otherwise it will present a new code.
Alternatively, the AirPlay settings on the destination device can be set to ask for a (custom) password instead. Then no code would be displayed, and user with the sending device should provide the password from knowledge.
AirPlay passwords should stay valid (per destination device) until something in the setup changes (like a password reset). Then it will ask for the new password (or pairing code if that was the change).
Please review these, including their troubleshooting paragraphs and links: