In Demon Slayer, Tanjiro is able to talk to the souls many times. Whenever he killed any demon, he is able to talk to their souls. When he was told to break the biggest rock, he is able to talk to the old disciples of masters who were best of all (Makomo and Sabito) and who were already dead (smile and vanish after teaching him). He also learned from them how to break the biggest rock.
How is Tanjiro able to talk to the souls?