Origin of "Given up the ghost"
Solution 1:
Ghost can describe a person’s soul or spirit (if you believe in such things), so if you give it up, possibly to some higher authority, you no longer have it and you die. Its use in that sense is very old, but the expression is probably more used now to describe less dramatic events, as in your example.
Solution 2:
It has a religious source:
And Jesus cried with a loud voice, and gave up the ghost. — Mark 15:37 (KJV) (BibleGateway)
However, it doesn't have a religious connotation in everyday use.
Solution 3:
Initially, I thought it's a bad translation from German, because German does have this slightly colloquial way of expressing that something breaks.
However, according to Wiktionary, the phrase is from the King James version of the Bible, Mk 15,37.
Solution 4:
There were Bible translations before the KJV, and this synonym for death appears in numerous places in Tyndale (1534). For example, Acts 5:5 reads: "When Ananias herde these wordes, he fell doune and gave vp the goost." Cf. Matthew 27:50: "Iesus cryed agayne with a lowde voyce and yelded vp the goost."