Hidden in ransack is a word for house, and the same word is buried in barn.

The source is a Scandinavian verb akin to Old Norse rannsaka. Etymonline breaks it into rann, "house," and saka, "to search," a form related to Old Norse sœkja, "seek." The American Heritage Dictionary glosses saka as "to search, seek," and Merriam-Webster connects it to Old English sēcan, the ancestor of seek. Literally, then, it meant "search the house."

Etymonline adds that the search was especially a legal one, for stolen goods. The Norse word could also already mean "to pillage," so the darker sense did not have to wait for English.

English picked it up in the middle of the 13th century as ransaken. Etymonline glosses the early verb with both meanings: to plunder, and to make a search. Merriam-Webster's earliest sense is the thorough search, and that sense survives in phrases like ransacking your memory or a drawer for your keys.

The modern spelling is a small puzzle. By ordinary sound change the word would have become ransake. Etymonline suggests the final -sack was perhaps influenced by the English verb sack. The link is only a suggestion, and sack is not the word's source.

The house element has relatives. Old English had the same root, and it survives, rearranged, in barn. Old English bereærn was a "barley house," with ærn a metathesized form of the root seen in Old Norse rann and Gothic razn, "house."

Ransack also had a cousin, ransackle, from the same source. Its past participle ransackled was altered to ranshackled by the 1670s, and that became ramshackle. The word was used mainly of carriages and houses and seems to have started in Scotland.

Today ransack mostly means a violent, untidy search by burglars or soldiers. The careful, house-by-house search is still inside it.