Where did they come from? Well, as I noted, "they" are probably not bacteria.
Bacteria evolved from something else I presume. Where that came from is, eventually, the subject of the study of the origin of life. I don't know where that came from.
If they were bacteria in the rock then we could suggest that they came from the same processes that may have occured on earth.