Nobody knows where mega stones came from. They appear to have deep connections with Omega Ruby/Alpha Sapphire. Mega stones are also only available in the dimensional timeline where Omega Ruby/Alpha Sapphire takes place, not the original Ruby/Sapphire, there the mega stones are just normal rocks, I heard this somewhere.