This is a sample of the Giving Up the Ghost tropes The term itself actually originates from the King James Version of the Bible
when Jesus was on the cross, His last words were
"Father, into your hands I commit my spirit." When he had said this, he breathed his last." (New International Version)
The King James Version of 1611, however, gave it the contemporary wording
"... and having said thus, he gave up the ghost." source
The trope is a spinoff version of the western version Winged Soul Flies Off At Death. The western version got first used in 1948 in a western animation
The 1948 short "Back Alley Oproar" with Sylvester and Elmer Fudd. Sylvester insists on singing when Fudd wants to sleep, and Sylvester eventually ends up on a cloud, complete with halo and wings.
as for the giving up the Ghost trope I am not certain when it first occured.