Make a gradient map layer, Layer → New Adjustment Layer → Gradient Map....
Image 1: Gradient map applied on image (photo source)
Obviously this effect can also be done without gradient maps. Here are some ways:
Make image grayscale, save that as a selection. Fill background color, load selection, make new layer fill foreground color.
make image grayscale, apply curves on that. This has the benefit of being able to control the interpolation per channel.
But there are more ways.. [1]: https://i.sstatic.net/RkaYa.png