I think your understanding is the same as mine, Grothenwell, though 'legitimated child' looks odd; I think it implies that the parents married between the birth and the baptism.
There's nothing unusual in an illegitimate child being known by its father's surname. In fact I think I've probably come across more cases of that than the opposite.
The kirk session (committee of minister and elders) would certainly have taken an interest in the pregnancy of any unmarried woman, or of any woman who had not been married long enough to preclude the possibility of pre-marital sex (antenuptial fornication is the usual phrase).
They would summon the woman and ask her who the father was. If she named someone, they would summon him to attend a meeting with her and question them both. If they were satisfied that the man was the father, or that the child had been conceived before the couple's marriage, the parties would have to perform a penance by standing in front of the congregation in church three times, and they would pay a fine that went into the poors' fund.
If the woman refused to say who the father was, or if the man absconded, the thing would grind on, usually inconclusively, though the woman could eventually perform her penance and be absolved from scandal, which would allow of her marrying someone else. Occasionally, in these cases, the child's marriage or death certificate will name the putative father.
The most interesting cases are the ones where the woman names a man, and he appears and denies paternity. The kirk session then seeks out evidence, which can be very entertaining. I have one, for example, where the session heard from several people who said that they had seen the parties, known to be lad and lass to one another, going into a barn where they remained, without lights, for two hours, about nine months before the birth of the child, and the kirk session concluded that he was indeed the father. The man absconded and eloped to Ireland with another woman, whom he married. The woman married someone else.
There were two reasons for all this. First, the openly acknowledged desire to stamp out sin in the form of fornication. Second, the less openly acknowledged desire to prevent the child becoming a charge on the parish poors' fund.