All of this does beg the question that if the computers of the 24th century, specifically in this case the computers of the Enterprise D and Voyager, are able to create sentient holograms, would that not necessitate them being sentient in and of themselves?
Not really. Human DNA molecules are not sentient, but they contain the necessary instructions for creating a brain that can become sentient. By the same token, a non-sentient computer could contain the instructions for creating a more complex, sentient computer.
Of course, the difference is that the Moriarty and EMH programs have to run
within the computer mainframes of their respective ships, so both vessels' computers do have the necessary processing power and complexity to run a sentient program. But sentience isn't just a matter of size. Sentience literally means, not intelligence, but consciousness, self-awareness, the ability to perceive one's own existence and feelings and responses. This is a particular type of cognitive architecture, one in which a system has feedback loops that make it aware of its own activity. One recent theory is that consciousness is the brain's simulation of its own activity and awareness -- it runs a model of itself
inside itself so that it can be aware of where its attention is focused and predict where its attention should go next in order to cope best with its environment.
So a Starfleet vessel's computer may be more than large enough to house a self-aware, conscious neural architecture -- i.e. to run a simulation of a neural system that contains a simulation of itself in turn -- but not normally be programmed to process information in that way. Figuring out how to make that kind of recursive, self-aware neural net operate stably was apparently a persistent difficulty within the Trek universe, given that Flint could never crack the problem and Soong was only able to do it twice, with the first one becoming psychopathic and the second having to be emotionally hobbled.
Also, it seems probable that Starfleet didn't
want its ships' computers to be self-aware. I'm sure that in the wake of the M-5 disaster (and perhaps the "Practical Joker" incident), Starfleet decided that it wanted its ships' computers to be reliably mindless and devoid of independent initiative. So there wouldn't have been any incentive to figure out how to program ships' computers with conscious architecture. They made them large and powerful enough that they could potentially host such programs, but did so for other reasons.
Then again, you'd think that, given the M-5 disaster, Starfleet would have safeguards in place to prevent the spontaneous creation of a self-aware program within them, so Moriarty and the EMH shouldn't have happened. Maybe it's because they both arose from the holographic systems, which would've been programmed separately and without such safeguards, thus allowing an end run around them.