Actualy, a rayquazza with dragon ascent can use a z-move but wont be able to mega evolve. We don't know why but I think mega ray with a z-move would be too overpowered. It only has the z-move option, not the mega evolution option.
Source: http://youtu.be/hQOQFKSmXSw
A ditto that has transformed into a mega evolution has the option but then it says there is no useable move.
Source: https://youtu.be/ngPl41Q6lwU
Almost any random Pokemon can't use alola raichu's signiture z-move, surge sparksurfer, because they aren't alola raichu. But thoxe random Pokemon can still use the electric z move, gigavolt havoc, if they have an electric move, so they don't count.This was just an example. The same could be said for any signiture z move and almost every Pokemon.