Very few were allowed to stay and continue fighting, mostly in the South where recruits were hard to find. Some of those who were kicked out re-enlisted on other regiments. Others served for the duration and told their stories later. Some never told their stories at all, one of the reasons they can only estimate the number of women who joined up as men to fight was 400. A few continued to live as men after the war because of better pay & more rights.
They managed to remain undetected for so long because; 1. Their medical examination to get in was brief; see if they have a trigger finger, can carry a pack & have teeth to rip the powder cartage open. 2. Their uniforms were ill-fitting to say the least. Not those tailored creations you see in the movies. 3. Solders rarely bathed so there was little chance of exposure (no pun intended) there. 4. Latrines were often too horrible to contemplate, so often people went off to do their "business" behind a good sized tree or something somewhere.
Overall an interesting read that i recommend for anyone who is interested in the US Civil War era untold women's stories.