It was certainly his being Catholic that led to James II being deposed. On the other hand I believe Charles II did not convert until near death.
If David Stuart was connected to the Royal Stuarts, I think the connection would have to go back to possibly a cousin, illegitimate sibling, etc of James I and VI. My understanding is James definitely was not Catholic and in fact was the target of several assassination plots by Catholic sympathizers. I believe Scotland actually started transforming from a Catholic country to a Protestant one during James' lifetime thanks to individuals like John Knox.
Wrong monarch
John Knox's famous sermon in St John's Kirk of Perth was delivered in 1559. James VI and I was not born until 1566. The monarch in 1559 was the absent Mary, Queen of Scots. When she returned to Scotland in 1562, Scotland was already mostly Protestant.
Mary Queen of Scots had numerous illegitimate half-siblings, any one of whom could have been your David's father or grandfather. See
https://en.wikipedia.org/wiki/James_V_of_ScotlandOne of these was James Stewart, 1st Earl of Moray, born about 1531, who was Mary's advisor, and was appointed Regent of Scotland after her abdication in 1567. He was a Protestant, and ensured that his half-nephew, King James VI and later I of England, was brought up as a Protestant.
So the transformation of Scotland from Catholic to Protestant was well under way when King James VI was born.