You can buy King's Quest V in the 1997 King's Quest Collection edition but keep in mind you need a Windows XP computer to run it.
You can also buy the 2006 King's Quest Collection which will have Dosbox mode built into the game but there is a save glitch in the directory file which makes it hard to save your game.
You can also buy the legal download of King's Quest V on the gog.com website or the PC Steam website.