His father, Sir James Dalrymple, 2nd Baronet, of Hailes, Haddingtonshire, Auditor of the Exchequer in Scotland, was a grandson of James Dalrymple, 1st Viscount of Stair; and his mother, Lady Christian Hamilton, was a daughter of Thomas Hamilton, 6th Earl of Haddington. The eldest of sixteen children, he succeeded to his father's baronetcy upon his death in 1751, inheriting Newhailes House in Musselburgh.
He was educated at Eton, and studied law at Utrecht. In 1748 upon his return to Scotland from Utrecht he was admitted an Advocate. It is said that as a pleader he attained neither high distinction nor very extensive practice, but he rapidly established a well-deserved reputation for sound knowledge, unwearied application and strict probity, and in 1766 he was elevated to the bench in the Court of Session where he assumed the title of Lord Hailes. Ten years later he was appointed a Lord of Justiciary.
He was twice married: (1) in 1763, to Anne, daughter of Sir George Broun, Lord Coalston, a Lord of Session, by whom he had a daughter, Christian (d.1838). He remarried (2) March 20, 1770, Helen (d. 1799), daughter of Sir James Fergusson, Baronet, of Kilkerran, Ayrshire, by whom he had another daughter, Jean (d.1803) who married her cousin, James Fergusson, Esq., and left issue.
Upon the death of Lord Hailes, his baronetcy passed to his nephew, James, 3rd Bt., the son of his brother John Dalrymple, Lord Provost of Edinburgh.
Lord Hailes's most important contribution to literature was the Annals of Scotland, of which the first volume, From the accession of Malcolm III, surnamed Canmore, to the accession of Robert I, appeared in 1776, and the second, From the accession of Robert I, surnamed Bruce, to the accession of the house of Stewart, in 1779. It is, as his friend Dr Johnson justly described this work at the time of its appearance, a "Dictionary" of carefully sifted facts, which tells all that is wanted and all that is known, but without any laboured splendour of language or affected subtlety of conjecture.
The other works of Lord Hailes include:Historical Memoirs concerning the Provincial Councils of the Scottish Clergy (1769)
An Examination of some of the Arguments for the High Antiquity of Regiam Majestatem (1769)
Remains of Christian Antiquity, 3 vols.
Remarks on the History of Scotland (1773)
Account of the Martyrs of Smyrna and Lyons in the Second Century, 1776
The Trials of Justin Martyr, Cyprian, etc., 1778
The History of the Martyrs of Palestine, translated from Eusebius, 1780
Disquisitions concerning the Antiquities of the Christian Church (1783)
editions or translations of portions of Lactantius, Tertullian and Minucius Felix.
In 1786 he published An Inquiry into the Secondary Causes which Mr Gibbon has assigned for the Rapid Growth of Christianity (Dutch translation, Utrecht, 1793), one of the most respectable of the very many replies which were made to the famous 15th and 16th chapters of the Decline and Fall of the Roman Empire. A Memoir of Lord Hailes is prefixed to the 1808 reprint of his Inquiry into the Secondary Causes.