The Gemara in סוטה teaches the idea of מתוך שלא לשמה בא לשמה, that when one performs Mitzvot for insincere reasons, it will lead to לשמה, for the sake of Heaven.
This is learned from Balak. He offered forty two sacrifices with the intention of cursing the Jewish people. Despite his negative intentions, he was rewarded with Ruth and ultimately the Mashiach descending from him.
This idea is certainly true for us as well. Even if our initial motivation is not for the right reasons, or we do things we don’t understand, or we don’t see the point in observing certain Mitzvot, it is important to just do it. Eventually, things will make sense and we will realize how important and meaningful the Mitzvot really are.