Let's say someone enlisted for two years and then was captured and held in a POW camp for 5 years. Would they continue to get a check or would the pay end when their two years were up?
Yes. Not only are POWs paid while in captivity, they can still receive promotions and other benefits for themselves and their families. And it's not just POW status: being MIA also counts.
Eligibility: Active duty Soldiers who are officially determined to be a Captive, Prisoner of War, Missing, Missing in Action, interned in a foreign country, captured, beleaguered or besieged by a hostile force, or detained in a foreign country against their will are entitled to receive or have credited to account the pay and allowances to which entitled when missing status began or to which a member becomes entitled later.
As to how long payments continue:
Payments continue though date of receipt by the Army of evidence of the death of the member or date of presumption of death made by the Secretary of the Army or the Secretary's designee, or date of return to Army jurisdiction.
And on promotions:
Promotions: POW personnel continue to be considered for promotion along with their contemporaries. Policy provides for each missing or captured officer/enlisted member to be considered for promotion to the next higher grade when they are eligible. The eligibility for officers is based on the date of rank in their current grade. For enlisted members, eligibility is based on time in grade and time in service.
A relatively recent example of this is CAPT Michael Scott Speicher, who was shot down and killed on the first night of Desert Storm. However, his remains weren't recovered and conflicting info on whether he survived and was being held by the Iraqi's after the war meant his case was re-opened as MIA instead of presumed dead. He was promoted from Lieutenant Commander (O-4) to Captain (O-6) in that time:
Conflicting reports from Iraq had, over the years, fueled speculation that the pilot, promoted to captain from lieutenant commander in the years he was missing, might have been taken into captivity either after parachuting from his jet or after a crash landing.