Under the Geneva Convention a prisoner-of-war may lawfully resume fighting once they have successfully escaped. Under Article 91:
The escape of a prisoner of war shall be deemed to have succeeded when:
He has joined the armed forces of the Power on which he depends, or those of an allied Power;
He has left the territory under the control of the Detaining Power, or of an ally of the said Power;
He has joined a ship flying the flag of the Power on which he depends, or of an allied Power, in the territorial waters of the Detaining Power, the said ship not being under the control of the last named Power.
In the course of effecting an escape Article 93 provides:
offences committed by prisoners of war with the sole intention of facilitating their escape and which do not entail any violence against life or limb, such as offences against public property, theft without intention of self-enrichment, the drawing up or use of false papers, the wearing of civilian clothing, shall occasion disciplinary punishment only.
In the scenario you describe, armed prisoners-of-war may attempt to escape and join the relieving forces. Once they do so they may lawfully use their weapons against their former captors. Clearly they have joined the relievers if and when they make physical contact with them but it could also be argued that they may have escaped when they became operationally joined to those forces.