While reading Malachi, I got stuck at the following verse:
"See, I will send you the prophet Elijah before that great and dreadful day of the LORD comes. 6 He will turn the hearts of the fathers to their children, and the hearts of the children to their fathers; or else I will come and strike the land with a curse" (Malachi 4:5-6).
Will this happen before the coming of Christ? Will Elijah (who I think is John the Baptist) remain on earth like a teacher training people to repent? or what exactly?
Do you see in chapter 3 a reference to purgatory in which the Catholics believe?
There are no references in Chapter 3 or any other chapter or verse in the Holy Scripture which in any way supports purgatory in the perspective of the Catholic Church or any other belief. When the prophet Malachi speaks about the Lord refining the sons of Levi or being pleased by the offerings of Judah, he is referring to their descendants, who at that moment and those who come thereafter have the privilege of willfully submitting to God before it is too late. Malachi 3:16-18 introduces an interesting dialogue, a beautiful doxology heard by God, from those who feared the Lord. Those who turned aside from the Lord are not integrated into their communication, not because they cannot communicate, but because their circumstances cannot change after their departure.
I think the question which you are asking is if this is a literal statement, a prophetic statement, both, or neither. The prophet Malachi, whom the church celebrates his feast day on September 5th, is one of the few who prophesied about St. John the Baptist (Malachi 3:1). St. John the Baptist can be a fulfillment of this prophecy because he is strongly identified as one who was in the spirit of Elijah, meaning, that because his demeanor, actions, beliefs, mission, and life were more than similar, but almost identical to Elijah, it is as if he was in the spirit of Elijah. Before the ministry of our Lord Jesus Christ spread, St. John the Baptist began his ministry by declaring that repentance must first pave the way towards salvation. It was not in itself enough to save, but it was the beginning towards the way of Salvation through Jesus Christ and the Holy Spirit. St. John's life ended on earth with his martyrdom. Therefore, he will not have a personal role in the Second Coming of our Lord Jesus Christ. However, the prophet Malachi's prophecy could have been indicating the coming of our Lord Jesus Christ as the Messiah and the role of St. John the Baptist to prepare the way. This is probably the strongest case for the interpretation of these verses.
The second possibility is that of a future prophecy of Elijah himself returning to complete his life on earth. Since Elijah was lifted up before his death, the prophet Malachi's prophecy could indicate that Elijah will return to complete his mission on earth before the Second Coming of our Lord. If this is not the case, then perhaps the last we would have known about Elijah's profound reappearance was during the Transfiguration of our Lord. It could be presumed that Elijah's repose took place after that event and that his appearance on the Mount of Transfiguration was to honor Christ as the Messiah whom all the prophets, along with Moses, have long anticipated.