The Federation should not have been surprised that their holograms developed sapience
We already know from TOS that Mutlitronic computers are able to develop sapience, with the M-5 computer being specifically designed to "think and reason" like a person, and built around Dr Daystrom's neural engrams.
However, we also know from Voyager that the holomatrix of their Mk 1 EMH also incorporates Multitronic technology, and from DS9 that it's also used in mind-reading devices.
Assuming that the EMH is designed to more or less be a standard hologram with some medical knowledge added in, it shouldn't have come as a surprise that holograms were either sapient themselves, or were capable of developing sapience. It would only be a logical possibility if technology that allowed human-like thought and reasoning into a hologram.
If anything, it is more of a surprise that sapient holograms like the Doctor or Moriarty hadn't happened earlier.
TNG had the strong implication that holodeck technology was pretty new, in the first season, at least at that level of sophistication. The early holodeck appearances are practically gushing about how realistic and "real" they feel, in a way they really wouldn't be doing if they'd had that sophisticated stuff all their lives. If it was really only around at this level for a few years, it's understandable that they wouldn't be prepared for all the implications right away. Look how long it took for us to adjust to the printing press, and we're struggling with the internet right now.
TNG had the strong implication that holodeck technology was pretty new, in the first season, at least at that level of sophistication.
It wouldn't be the first time TNG-1 would be retconned by DS9/VOY/ENT/TNG-3+ though. While less extreme It was a bit like the early DIS/PIC of its day.
Yeah, the first scene where Riker is in awe of the holodeck also says Data was in the class of 78, Riker is reluctant to accept Data's personhood (as initially planned), and since they hadn't introduced the replicators yet, Data describes the holodeck as using transporter tech in a way that sounds very clumsy and patronizing now.
After that they mostly stick to holodecks just being new on ships, and not usually controlled by a computer as sophisticated as the Enterprise's.