I'm not sure how good an example Welsh is. Wales was essentially passive after the late 15th Century, and so the Welsh-speaking population didn't really get hit with any overt discrimination until the School System began to be standardised and made compulsory (English being a requirement for advancement being more passive than outlawing the teaching of Welsh as happened in the late 19th/early 20th Century). Really Wales went through at most 2 generations of actual anti-welsh legal discrimination (my Grandmother was forbidden to speak Welsh at school and her father didn't speak it at home IIRC, but I'm pretty certain she's mentioned the generation above that being bilingual. By the time Dad's generation came along our family had lost the language but it was coming back to the schools).
Irish went through a much longer period of overt discrimination, and while ending it earlier and mitigating the famine will help, it does bear thinking that the decriminalisation of much of the Highland culture that occurred around this time hasn't had much of an effect towards preventing the decline of Scots Gaelic.
I meant specifically the school system, sorry if I didn't make that obvious, but I was posting quite late at night, apparently past what I should have been awake. Welsh is the healthiest of the Celtic languages, and part of that is Welsh language immersion schools, attended by 62000 students in the 11-12 school year, between a fifth and a quarter of all Welsh students. Compare this with 35000 students attending comparable Irish-language schools in both sections of Ireland (a bit more than six percent in the Republic and less than half a percent in NI). Moreover, about ten percent of NI's population reports having knowledge of Irish, more than ninety percent of which are traditionally nationalist Catholics. This represents about one-fifth of the Catholic population, which suggests that languages sometimes thrive under a perceived threat, that is, being part of a state with a vast majority of English speakers and no attachment to Irish.
Another factor would be the lack of a similar sort of population loss as the Famine or the Clearances. AFAIK, Welsh emigration hasn't been disproportionately large like Irish or Scottish emigration, and that must be a huge factor in language loss, particularly when you take into account that the Famine was most damaging precisely in those areas where Irish was most spoken, the agrarian provinces of Munster and Connacht.
Part of the problem with Scottish Gaelic, IMO, is that it had already been marginalized for centuries by the Scottish elite. Combine that with risings against Hanoverian rule and lairds pushing out poor folk to make more money off sheep and it's a poor situation. Plus, Gaelic's historical range is rather smaller than those of Irish or Welsh, being pretty well restricted to the Highlands and Hebrides since the fifteenth century. Any way you look at it, it's a much less positive story for Gaelic, with everything against it.