Based on this article, the movie Split was inspired by the real life story of Billy Milligan. He supposedly had 24 personalities as part of DID, and thus the 24 personalities stuck...
It has intrigued him (Night.M.Shyamalan) since the 1990s, when he heard that Titanic director James Cameron was trying to make a movie about Billy Milligan, the first man to successfully use the disorder as a legal defence.
"I've loved the subject for a long time. I remember I heard that James Cameron was going to make a movie about DID, based on the book The Minds Of Billy Milligan. And I was, like, 'Oh my god, that's going to be amazing. I want to grow up and make that movie.'"
Similar to the Teacher being the 24th which bound all the personalities together for Milligan, the Beast was the 24th personality for Kevin.