It can sometimes be difficult to find out who the parents of an illegitimate child were, because the baptisms of such children are often missing from the parish registers.
The best chance of finding about more about them, at least until the middle of the 19th century, is in the records of the Kirk Sessions.
Every Church of Scotland parish has a Kirk Session, which is a committee nade up of the minister (usually referred to in the KS records as 'Moderator' or 'Modr') and elders. This committee manages the business of the parish kirk, including maintaining the kirk and manse, appointing minister and elders, sending representatives to the higher tiers of the kirk (Presbytery, Synod and General Assembly), collecting money, providing mortcloths, distributing money to the poor of the parish (until 1845 when the new Poor Law established Parochial Boards to look after the poor), and so on.
However almost every KS spent a lot of time on 'discipline', which was dealing with fornication and its consequences. If the KS learned that an unmarried woman was pregnant, she would be summoned to a KS meeting and asked who the father of the child was. The father would then also be summoned and the couple confronted with one another at a KS meeting. If he admitted paternity, and accepted responsibility for supporting the child, the couple would be rebuked, and often made to stand on the 'stool of repentance' in the kirk during up to three services so that the entire congregation would see them doing penance. They would them be fined, 'absolved from the scandal', and 'readmitted to church privileges'.
If the alleged father failed to appear, or absconded, or appeared and denied being the father, the KS would take various steps to try to determine the truth. Some of these processes can contain a lot of detail about the people involved and their circumstances and relationships to others. (They can also be extremely entertaining - I have not infrequently found myself stifling a giggle or a gasp of astonishment while perusing a case in a KS minute.)
Sometimes a recently married couple would be summoned to answer for the sin of antenuptial fornication, and dealt with in similar terms.
If it was a case of adultery rather than simple fornication (or might be - have found one where the KS decided to wait until the baby was born before they could work out whether it had been conceived before or after the death of its father's wife), the matter would be referred to the Presbytery, who rarely did much more than talk about it and then refer it back to the KS to deal with.
Note that the practice was dying out by the second half of the 19th century, so the KS records often don't help with illegitimacy after the start of civil registration. Also they are, as one would expect, more comprehensive in rural than in urban parishes.
So where does one get hold of all this information?
The KS records were almost all collected by the Scottish Record Office, which then became the National Archives of Scotland and is now the National Records of Scotland. They have all been digitised, and some of the original books have been returned to local archives where the NRS is satisfied that they will stored in the right conditions and well looked after.
To find out whether the particular KS records in whch you are interested have survived, go to the online catalogue at
https://catalogue.nrscotland.gov.uk/nrsonlinecatalogue/search.aspx, type the parish name in the 'Search for' box and 'CH2' in the 'Reference' box. You can also search for dissenting kirks' KS records by typing 'CH3' in the 'Reference' box. You will need the full reference to look up the digitised version in the Virtual Volumes.
All the digitised versions are available to consult in the Historical Search Room in General Register House in Edinburgh, and in those local archives which have made an appropriate agreement with the NRS (Aberdeen, Alloa, Glasgow, Hawick and Inverness that I know of; there may be others).
Scotland's People has stated its intention of making the digitised KS records available online, but there are still some technical hurdles to be overcome. In the meantime, you either have to go in person to one of the archives which has access to the digital images, or get someone to go on your behalf. If you want to hire a professional searcher, see
https://www.asgra.co.uk/.