Hadith of Abu Hurairah رضي الله عنه;
The Prophet said ﷺ: Let not any one of you precede Ramadan with fasting a day or 2 before except for a man who used to fast at that time then he is able to fast on that day. (Except a man who used to fast regularly in that time, then he fasts on that day)
Shaykh ‘Ubayd al-Jaabiri حفظه الله said:
The Messenger ﷺ forbade that the Muslim fasts a day or 2 days before Ramadan. The foundation of this prohibition and forbiddance that is further emphasised in a narration in Bukhari, that is from Ammar ibn Yasir رضي الله عنهما, that he said whoever fast a day of doubt then he has disobeyed Abul Qasim (Messenger ﷺ)
This narration which Bukhari mentions shows us that, it is not allowed to go against the Messenger ﷺ by fasting a day or 2 before Ramadan except for a man who used to fast or known to fast those days. The meaning of this is Whoever has to make up fasts before Ramadan, For example, If he has not fulfilled the fast in the previous Ramadan, then he can fulfil those fasts even in these 2 days or any time before the coming of Ramadan. It may be a person who has made an oath to fast so therefore it is allowed to expiate his oath even in these 2 days meaning even before Ramadan. Likewise, it could be a person who is fulfilling an expiation and must fast for his sin to be forgiven, then he is allowed to fast just before Ramadan. Furthermore, it could be a person who did not actually sacrifice the slaughter in a time of Hajj Tamattu or Qiran, where he is supposed to slaughter, so he has to fast, so he can fulfil those fasts in those days preceding Ramadan (if he has not done so already). Or he could be a person fasting Mondays and Thursdays and those days coincide before Ramadan, then there is no harm upon a person to fast on those days.