Finn going on a side mission wasn’t “for no reason”, it was to grow him as a character into becoming a hero.
At the start of the TFA, Finn hates the First Order but responds by trying to flee (ie self preservation is his primary motive). His rescue of Poe is completely incidental to his desire to escape. He even tries to flee mid movie rather than stay with Rey and Han. But by the end of TFA, he has become slightly heroic....ie he’s willing to risk his life to save people who have become his friends (Rey and to a lesser extent Han). At the start of TLJ, Finn is still only willing to risk his life to help save Rey. However, he eventually agrees to take part in a mission that in addition to helping Rey will help save the Resistance against the First Order. During his time on the casino planet, he is introduced to the realities of the universe from the war profiteers to the lowest stable slaves. He is even tempted back into a self-first philosophy (every side is evil according to him) by the codecracker but ultimately rejects it to continue on his path to becoming the ultimate selfless hero. By the final chapter of TLJ, Finn is willing to literally commit suicide to take out the First Order’s giant gun in order to save the Resistance and a bunch of people he doesn’t really know simply to preserve the struggle against the First Order.