c. 1200, "price, value," from Old French cost "cost, outlay, expenditure; hardship, trouble" (12c., Modern French coût), from Vulgar Latin *costare, from Latin constare, literally "to stand at" (or with), with a wide range of figurative senses including "to cost," from an assimilated form of com "with, together" (see co-) + stare "to stand," from PIE root *sta- "to stand, make or be firm."
The idiom is the same one used in Modern English when someone says something stands at X dollars to mean it "sells for X dollars." The meaning "equivalent price given for a thing or service rendered, outlay of money" is from c. 1300. Cost of living is from 1889. To count the cost "consider beforehand the probable consequences" is attested by 1800.
In phrases such as at all costs there may be an influence or echo of obsolete cost (n.) "manner, way, course of action," from Old English cyst "choice, election, thing chosen." Compare late Old English alre coste "in any way, at all."
suffix forming adjectives from nouns and meaning "having qualities of, of the form or nature of" (manly, lordly), "appropriate to, fitting, suited to" (bodily, earthly, daily); irregularly descended from Old English -lic, from Proto-Germanic *-liko- (Old Frisian -lik, Dutch -lijk, Old High German -lih, German -lich, Old Norse -ligr), related to *likom- "appearance, form" (Old English lich "corpse, body;" see lich, which is a cognate; see also like (adj.), with which it is identical).
<a href="https://www.etymonline.com/word/costly">Etymology of costly by etymonline</a>
Harper, D. (n.d.). Etymology of costly. Online Etymology Dictionary. Retrieved $(datetime), from https://www.etymonline.com/word/costly