Which is it?
It was the later. A close relative of the Beagle's captain, Robert Fitzroy, had gone insane as a ship's captain and had committed suicide. Fitzroy was worried about a familial tendency to insanity and wanted a gentleman companion to dine and have conversation with. (The authoritatian ethos on British naval ships of the period prevented the captain from socializing much with members of the crew, even other officers.)