It is a common misconception that all sacred music is liturgical. The answer is false: while there is significant overlap, the two categories are distinct.
Sacred music is any music composed with a religious or spiritual purpose. This includes works written for worship, but also pieces intended for:
Liturgical music is a subset of sacred music specifically composed for use within a formal religious rite or service (the liturgy). It follows prescribed texts, structures, and rubrics (e.g., the Mass, the Divine Office, hymnody for specific feast days).
All liturgical music is sacred, but not all sacred music is liturgical. A choral anthem performed in a concert hall is sacred but not liturgical; the same piece sung during a church service becomes liturgical in that context.