Kastalsky was born in Moscow to protoiereus Dmitri Ivanovich Kastalsky (1820–1891). He studied music theory, composition and the piano at the Moscow Conservatory. In 1887 he started teaching piano at Moscow Synodal School, and in 1907-10 was precentor of the Moscow Synodal Choir. He was director of Synodal School from 1910 until 1918 when the school was transformed to the National choral academy (in 1923 it merged with the choral faculty of the Conservatory), and the choir was forced to move from sacred to folk repertory. In 1922 he became professor of the Moscow Conservatory.
Kastalsky wrote his first choral works in 1896. Up to 1917 he wrote over 130 works and established himself as a noted composer of the neo-Russian style, as one of the founders of the New Direction in Russian sacred music (side by side with such composers as Sergei Rachmaninoff, Alexander Grechaninov, Pavel Chesnokov and others).
He was also a scholar of ethnography and strove to reveal the laws of national style by studying Russian folklore. This resulted in such books as Peculiarities of the Russian folk musical system (M.,1923) and Fundamentals of folk polyphony (M.- L., 1948).
Requiem for Fallen Brothers is the most important musical work by Kastalsky. It was written in 1915-16 and devoted to the victims of the First World War. The composition had three versions. The version for soloists, choir and organ, previously unpublished, was printed by the publishers “P. Jurgenson” only in 2014, commemorating the 100th anniversary of the First World War.