The Corpse King is a recreation of the mind of Artoria Pendragon created using Logos React, similar to how Add's personality is a copy of Kay. She was created for the purpose of reviving Artoria in modern times, by combining the Corpse King as the mind, Gray as the body, and Saber summoned in the Holy Grail War as the soul.
The Corpse King dwells in the secret tunnels beneath the Blackmore Cemetery.
Lord El-Melloi II Case Files
When they enter a simulation of Blackmore Cemetery inside of Logos React, Lord El-Melloi II and Gray venture into the tunnels beneath the village via the church where they encounter the Corpse King. The Corpse King tells Gray and Waver that it's too early and that the future king hasn't awoken, and that Gray is supposed to be on the surface, whereas she is meant to be underground.
The Corpse King has the ability to give life to an entire army of skeletal soldiers, albeit barely functioning. Magical energy taken from the surroundings are inserted into records and use skeletons as a medium. In a sense, they're almost like failed Servants. The skeletons are powered by od from the villagers of Blackmore Cemetery. As the villagers pray to the Black Madonna statue in the village's church, it is equivalent to offering up their own magical energy. As a result, the Corpse King's skeleton soldiers can regenerate indefinitely, regrowing broken parts like a video being played in reverse.