I have noticed from different published articles that mathematical equations may or may not be ended by a comma or a period (depending on their position in the text). Which is the best practice?
Yes it is good practice. You should read the papers of people are well known to be excellent expositors like Serre and his students Atiyah and Grothendieck (who also had quite a few students). They all endorse commas and periods. Perhaps the best guide to mathematical writing is https://www.youtube.com/watch?v=ECQyFzzBHlo (Serre). Let me emphasize how authoritative Serre's opinion is: he is easily the most influential mathematician of the postwar period.