Wow, a "real" question...haven't had one in a long time...
Unfortunately, there is no official material about how they came to be, we can only assume they were created by Mokona as part of his/her "all grand plan". This is one of the many things that is up to fans to imagine about. However, Mokona and the Mashins do show up in another CLAMP series called TSUBASA. I haven't read/watched that series, but there might be some information there (although anything in TSUBASA should be treated as an "alternate universe" since it's really a mix and match of all the CLAMP series put into 1 story).
There are lot of fan fics with original stories on how they came to be though, if you're after fan interpretation. Here's a good place to start.