Who built the tomb for Balin, buried him in it, and inscribed "Here lies Balin, son of Fundin..." on it? Wasn't he, and every other dwarf with him, killed by orcs?
Balin died before they were all slain
Balin having gone to look into Mirrormere, which was out the Eastern gate of Moria, had been shot by an Arrow. His body was however recovered and later the Dwarves must've built him a tomb. However their doom seemed to be reasonably after his death. This is evident given the Dwarves were slain at the West gate, having travelled through Moria before being killed in the end.
‘The first clear word is sorrow, but the rest of the line is lost, unless it ends in estre. Yes, it must be yestre followed by day being the tenth of novembre Balin lord of Moria fell in Dimrill Dale. He went alone to look in Mirror mere. an orc shot him from behind a stone. we slew the orc, but many more … up from east up the Silverlode ... I wonder what happened afterwards; but there is no time to puzzle out the last few pages. Here is the last page of all.’ He paused and sighed.
‘It is grim reading,’ he said. ‘I fear their end was cruel. Listen! We cannot get out. We cannot get out. They have taken the Bridge and second hall. Frár and Lóni and Náli fell there. Then there are four lines smeared so that I can only read went 5 days ago. The last lines run the pool is up to the wall at Westgate. The Watcher in the Water took Óin. We cannot get out. The end comes, and then drums, drums in the deep. I wonder what that means. The last thing written is in a trailing scrawl of elf-letters: they are coming. There is nothing more.’ Gandalf paused and stood in silent thought.
The Fellowship of the Ring - Book II, Chapter 5: The Bridge of Khazad-Dûm
Although Gandalf skips a couple of pages, we can guess that the tomb was either built, or Balin laid there either before they were trapped, and the dwarves only returning there after reaching the east gate, or building it during their final stand in honour of their attempts and their King Balin.
It’s worth remembering that initially the dwarves were successful at driving out the Orcs, however they returned with greater force and swept away the unprepared Dwarves.
The tomb also, certainly, existed in the books:
Their feet disturbed a deep dust upon the floor, and stumbled among things lying in the doorway whose shapes they could not at first make out. The chamber was lit by a wide shaft high in the further eastern wall; it slanted upwards and, far above, a small square patch of blue sky could be seen. The light of the shaft fell directly on a table in the middle of the room: a single oblong block, about two feet high, upon which was laid a great slab of white stone. 'It looks like a tomb,' muttered Frodo, and bent forwards with a curious sense of foreboding, to look more closely at it. Gandalf came quickly to his side. On the slab runes were deeply graven: 'These are Daeron's Runes, such as were used of old in Moria,' said Gandalf. 'Here is written in the tongues of Men and Dwarves: Balin son of Fundin Lord of Moria.' 'He is dead then,' said Frodo. `I feared it was so.' Gimli cast his hood over his face.
ibid. - Chapter 4: A Journey in the Dark
Dwarves are good at working stone, and had some time between when Balin fell and when they were finally wiped out. In LotR, the Book of Mazarbul says:
'The first clear word is sorrow, but the rest of the line is lost, unless it ends in estre. Yes, it must be yestre followed by day being the tenth of novembre Balin lord of Moria fell in Dimrill Dale. He went alone to look in Mirror mere. an orc shot him from behind a stone. we slew the orc, hut many more ... up from east up the Silverlode. The remainder of the page is so blurred that I can hardly make anything out, but I think I can read we have barred the gates, and then can hold them long if, and then perhaps horrible and suffer. Poor Balin! He seems to have kept the title that he took for less than five years. I wonder what happened afterwards; but there is no time to puzzle out the last few pages. Here is the last page of all.' He paused and sighed.
The timing isn't explicit, but Balin was killed before most of the Orcs had even entered Moria or the Dwarves were aware of their peril -- otherwise, Balin would have been a lot more careful. The period between when Balin died and the orcs were inside Moria in numbers may have been many weeks or even longer -- Moria was designed to withstand siege.
We know that Dwarves were very solicitous of the bodies of their dead leaders, so that they would build a tomb while they were fighting off what might have been just another incursion of orcs doesn't seem unreasonable.