If using gnu sed:
$ cat animals
dog
cat
dolphin
cat
$ sed "/cat/ { N; s/cat\n/giraffe\n&/ }" animals
dog
giraffe
cat
dolphin
cat
- match a line with (/cat/)
- continue on next line (N)
- substitute the matched pattern with the insertion and the matched string, where
& represent the matched string.