What is the function of the ghost in the earlier scenes of act I, scenes ii and iv, and why do you think Shakespeare has the ghost wait to speak to Hamlet until the end of act I?
The ghost's functions in Act I, scenes ii and iv, are related to its function in Act I, scene i. In that first scene the ghost's appearance sets the action in motion for the entire plot. Horatio and the others see the ghost and are greatly disturbed by it. (In the Shakespearean world, a disruption or oddity in one realm is echoed in another. If a ghost shows up somewhere it isn't supposed to be, there's a problem somewhere else, specifically the realm of the living, especially Denmark.) In scene ii accounts of the ghost are brought to Hamlet; here its functions are to put the burden of fixing things on Hamlet, and to undercut Claudius' big speech opening scene ii. Scene iv finishes this "anointing"—Hamlet sees the ghost and realizes just how much is wrong.
Is the second question why didn't Shakespeare let this happen? If so, I'd say it is to allow Hamlet's emotions to build, and the audience's suspense along with it.
In Act 1 Scene i, the "Ghost" had appeared at a chilling, misty night at Elsinore Castle in Denmark, right in the view of vision of the watchmen. This supernatural apparition had strong implications that something is happening in Denmark that would be detrimental and that strange ghost of deceased King Hamlet served to show the influence that he had covered around the whole empire and indicate that his death was not what it seems to be and might have already affected the balance of nature and order, chaos would break out in a flash. It also heightens the fearful anxiety that had engulfed the kingdom after the change in leadership and tells the audience that Denmark would never be the same again. It gives a sense of mystery and ominous feeling pervading the atmosphere. It is an ill omen that beckons turmoil and troubles to Denmark future, comparing it to the supernatural omens and strange elements that had happen after the assassination of Julius Caesar by Brutus and the rebels in ancient Rome. It also foreshadows some internal tragedy is going to break up into a mega-catastrophic disaster. It gives a presage of many horrible things to come.
In scene II, the main purpose of the ghost was to add more burden to Hamlet's taxing life as he hopes to speak to the apparition among his many court matters that he had to settled.
In Scene IV, the re-appearance of the "Ghost" brings along terms like uncertainty of the unknown, unanswerable questions, nagging thoughts, truth and spirituality or in short, spiritual ambiguity that had clouded Hamlet's soul after seeing the apparition himself, not knowing if it was a demon, who is just trying to tempt him to Hell and cause massive destruction or the real King Hamlet himself. It would dig inside his moral conscience and wrenching and disturbing consequences of moral truth that would change his life forever in his quest of self-answer and self-knowledge that had been hurting his heart ever since.