John Milton wrote “Lycidas” as a contribution to a group of poems mourning the death of Edward King, a classmate of his at Cambridge University. In this poem, Milton follows the conventions of the pastoral elegy.
The term "elegy" originally was Greek, referring to a poem accompanied by the music of a flute, as opposed to the lyric, which was accompanied by the lyre. As many poems in the elegiac mode were sad, the term gradually evolved to mean a melancholic poem, especially one mourning a death. Since "Lycidas" is a poem mourning a death, it fits the standard genre of elegy.
The pastoral genre, exemplified by the Hellenistic poet Theocritus, is set in an imaginary rural environment, populated by shepherds and shepherdess, rural cottages, and idyllic farms. It is not intended as a literal portrayal of rural life, but as an imaginary world of beauty and innocence. In the first part of "Lycidas," Milton imagines King as a shepherd in a pastoral setting, portraying Milton and his friend as shepherds creating songs.
Thus as the poem is an elegy in a traditionally pastoral setting, it is a pastoral elegy.