Prescriptions are occasionally written for OTC meds so that they can be covered by medicaid, FSAs, etc.
Also, NSAIDs are not just for pain control. They are also anti-inflammatory (e.g. used for pericarditis) and can be used in more obscure circumstances such as closing a PDA in an infant.