Two main cases:
1) Lower grades (i.e. k-6) will often keep a bunch of books in the classroom, so the kids have a selection available if they want to (or have to) read. This way they don't have to make a trip to the library to pick out a new book, as it can often be kinda difficult for a kid to find time to visit the library outside scheduled classroom visits, and that's an extra step between a kid wanting to read and being able to, that teachers would rather not have (since it might mean less reading). Often these sorts of classroom libraries are stocked by the teacher. Such libraries may be left behind by teachers retiring or otherwise leaving teaching, and the teacher replacing them may keep part or all of the library.
2) Upper grades, where you start having dedicated English or "Language Arts" classrooms, will often keep classroom sets (that is, enough books for every kid to have one at once) of the books the classes teach. Often there will also be other individual books, plus maybe some classroom sets of books that the teacher doesn't teach (maybe they switched their program up a bit, or maybe they're left overs from a previous teacher)—a teacher may keep these around or stock such a small library themselves and let kids borrow them, because being an upper-grades English teacher tends to correspond with liking and wanting to encourage reading. Some lower grade (well, properly, middle-grade or what you might call "upper elementary", but I'm trying to keep it simple) classes may also keep a few classroom sets once the kids can read independently and full books are being taught to and read by the entire class at once (a 4th grade classroom might have a classroom set of Charlotte's Web or something like that)
[EDIT] LOL, on reflection that was really three cases with some overlap (classroom sets of books; miscellaneous books intended to be read in class; miscellaneous books intended to be borrowed) so, uh, worst structure for a comment ever, I guess.