If you modify your use of For Xml Path, it will do the unescaping for you and you won’t need to resort to using the Replace function:
, Stuff(
(
Select '; ' + IsNull( D2.SelectedComments, '' )
From #StudentDetails As D2
Where D2.Stud_PK = A.Stud_PK
And D2.CourseNo = A.CourseNo
And D2.Section = A.Section
For Xml Path(''), type
).value('.', 'nvarchar(max)')
, 1, 2, '') As SelectedComments