Do course buyouts happen in pure mathematics?
The NSF won't generally allow a faculty member to take more than 2 months of salary per year from NSF grants.  Since you would typically want summer salary before buying out of teaching, this effectively makes it impossible to buy out of teaching on NSF funding alone.  

However, if you combine your NSF funding with funding from other agencies (such as the Office of Naval Research, Army Research Office, National Geospatial Intelligence Agency, DARPA, DOE, etc.), it's certainly possible to have enough months of grant support to buy out of teaching during the academic year.  Whether your program manager will agree to pay for this and whether your institution will allow it are still questions that you'd have to answer.