Strictly speaking, it refers to text that is inscribed on a tombstone or plaque, but it may also be used in a figurative sense.
Some epitaphs are specified by the person themselves before their death, while others are chosen by those responsible for the burial.