I can only speak to USNA's programs -- I would guess that USMA's are similar, but that's only a guess.
USNA automatically considers candidates who are deemed not qualified academically for USNA for NAPS and Foundation (private prep schools). If you are offered a spot, you can decide whether or not to accept. If you successfully complete either program (academically and otherwise), you are essentially guaranteed a spot in the following year's USNA class.
Whether you're offered a NAPS/Foundation spot is up to the Admissions Board at USNA. Basically, they are looking for people whom they believe have the potential to succeed at USNA but need some additional academic prep. Normal indicators for this are high SAT, low class rank/GPA; or the converse. Maybe doing well academically but not taking the highest level courses (i.e., getting an A in Algebra II but not having Pre-Calc or Calc). It is a very individualized determination.
Again, not sure how USMA works, but probably similar.