It's all based on luck, friend.
If you want tips for beating Expert stages:
• Make as many matches as possible, as fast as possible. Lucario has one of the longest times at 2:00, so take advantage of that.
• Be smart with your Megas. I personally used Mega Lopunny to catch him. Try lining them up like so ([L]= Lopunny, [0]= other Pokémon):
[L] [L] [0] [L] [L]
Then drag a fifth Lopunny into the center to effectively clear five rows. If you are using Mega Kangaskhan, then do the same thing but vertically. Those are probably the best Megas outside of maybe Slowbro for catching Lucario.
• Use types to your advantage. Catch Pokémon like Chatot, Espurr and Mew that can deal heavy damage to Lucario. If you have a Flying or Psychic Mega, use that.
• Don't stress if you lose.Just keep trying. You'll get faster and faster and eventually you'll end up with a decent catch rate. Also, your Pokémon still gain Exp from a defeat, so use this as an opportunity to grind levels.
• Trust the RNG. I caught Lucario with a 17% catch rate; it's all based on luck.