How does the whole EX/GX thing work? (Pokemon TCG)
The only things needed to know the rules of a particular card are just a rulebook[1] and the card itself.

Regarding EX cards, there's nothing written on them about limiting them to one per deck so this rule from rulebook applies[1]:


  When you are building a deck, you can have only 4 copies of a card with the same name in it, except for basic Energy cards.


Also the text "Evolves from X" on Evolution cards (= not Basic) is important because it's the name of the card you can only play the Evolution card onto. In your case, Lucario-EX is Basic, M Lucario-EX is Mega evolution that "Evolves from Lucario-EX" so you only need Lucario-EX in play to be able to evolve to M Lucario-EX, any other combination won't work[1].

 

In the rulebook there are appendices for both Pokémon EX and Mega Pokémon explaining the rules that are written on the cards if you'd like to know more.

In tournament, as long as you have at least one Basic Pokémon card in your deck, you can't be punished for playing an impossible evolution cards (like Riolu+Lucario with M Lucario-EX), you would just have cards in your deck that you are not able to play under any circumstances (you can't put M Lucario-EX into play without Lucario-EX). On the other hand, don't forget to check the actual format of the tournament, all premier events nowadays use either Standard format (cards released in last ~24-36 months) or Expanded (Black &amp; White and newer)[2] and your M Lucario-EX is legal only in the latter one. If you showed with M Lucario-EX on a Standard event, than you would really have an illegal deck[3].

As you pointed out, the difference between Pokémon EX and Pokémon GX is that the former ones are always Basic whereas the latter ones are always the stage they are supposed to be[1] (except for Tag Team GX cards which are also always Basic). However this difference is conceptual and has no impact on the game itself. You just read the cards and you are fine.



[1] Pokémon Trading Card Game Rules (Sun &amp; Moon rulebook)
[2] Play! Pokémon TCG Rules and Formats
[3] Pokémon TCG Penalty Guidelines