A portrait of celebrated 18th-century poet Robert Fergusson has been discovered at a Scottish castle.