the murder was the actual crime Data was supposed to solve (which he does)
No. The murder was an independent program. The opponent with the ability to defeat Data was Moriarty, not the woman who killed her husband. Data and Geordi were puzzled that the holodeck was running a program that they didn't tell the computer to run. Data didn't even want to waste time on it; he stuck around and solved the murder only to humor Geordi.
Otherwise the inclusion of the murder is totally random and doesn't have anything to do with anything.
The point is that Data, Geordi, and the Enterprise
crew are not the only ones who can access the computer and run programs. The murder mystery program was initiated by Moriarty, who was probably experimenting to see what he could do with the computer.