A basic 9-speed chain doesn't cost all that much so in most cases this wouldn't be worth it, especially since having several damaged links kind of implies a chain that's pretty beat up and in imminent need of replacement anyway.
But, you can do it safely if you want to. A good approach here would be to take advantage of the fact that 9-speed KMC MissingLinks are designed to be fully compatible with both Shimano and KMC 9-speed chains, which implicitly means KMC designed their 9-speed inner link thickness to exactly match Shimano. So if you're replacing a damaged segment, get a scrap of any KMC or Shimano 9-speed chain, trim it so that it's got an inner link on both ends, and use 9-speed MissingLinks to connect it. With two-piece connecting links, if it snaps together snugly such that you can't easily separate it by hand, you can be pretty confident no forces from riding will be able to separate it either.
Another approach would be using Shimano 9-speed replacement pins, and then prepping the KMC part to be inner links, since the replacement pins have to go through Shimano outer links only. This would physically go together but it would be against Shimano's warning of only connecting the "leading" link this way, supposedly for strength purposes.
SRAM 9-speed PowerLinks work the same way for most intents and purposes, and a lot of people use them without issue for any 9-speed chains.
What you shouldn't do is press a pin that's been partially driven out of a 9-speed chain back in to the outer link, because it can cause failure.