Some countries (e.g. the USA) have a “Criminal Code”, which puts most/all of their criminal offences together into a single document. Scotland doesn’t have one.
A crime (or “offence”) in Scotland can be put into one of two broad categories: common law offences and statutory offences.
The way I tend to summarise common law offences are “they’re crimes because they just are“. Common law crimes – like assault, theft, murder, fraud and breach of the peace – were not created by Parliament, and as such are not defined in legislation.
In 1797, Baron David Hume (whose statue, lucky toe and all, stands outside the High Court of Justiciary in Edinburgh) used his research into High Court decisions to produce an authoritative account of the state of Scottish criminal law at the time. As such, we suddenly had an explanation of all the crimes known in Scotland. Hume’s Commentaries, updated posthumously in 1844 and since, is regarded as the authoritative text on Scottish criminal law.
Since this initial text, the common law – how we define offences, rules of evidence and procedure etc – has been developed over hundreds of years, and is a constantly evolving process. This development tends to come from decisions of the High Court of Justiciary (most commonly the Appeal Court), but can also come from the UK Supreme Court when cases are (rarely) referred there.
The constant evolution of the common law means that staying on top of case law developments as much as possible is extremely important for criminal lawyers. It’s also why there’s not much of a second-hand market for law textbooks, seeing as they’re usually outdated by the time they hit the shelves.
If an offence has been created by a “statute” – a piece of legislation (e.g. an Act of the UK or Scottish Parliament) – then it’s a statutory offence. Confusingly, these can also be called “enactments” (in the sense that Parliament enacts legislation).
An example of a statutory offence is “Threatening or abusive behaviour”, as it was created by s38 of the Criminal Justice and Licensing (Scotland) Act 2010.
Statutory offences are subject to interpretation, and appeals can sometimes focus on what “Parliament’s intention” was in drafting a particular section (for example, see the appeal of AMI v PF Glasgow from 2012).
Legislation can be found at https://www.legislation.gov.uk.
Always be sure that a particular piece of legislation applies to Scotland, and that it’s up to date. The “Show Geographical Extent” option on legislation.gov is an easy to answer the former question, and (touch wood) there appears to have been a concerted effort made recently to ensure that all legislation on the site is up to date.