Try these queries:
select ID, string_agg(c.Slno, ',') as Details
from #temp
cross apply openjson( Details, '$') with ( v varchar(max) '$.CID' )
inner join #CIDValue c on c.CID = v
group by ID
select ID, concat( '[', string_agg( j, ','), ']') as Details
from #temp1
cross apply string_split(Details, ',') s
inner join #CIDValue1 c on c.Slno = s.value
cross apply (values ((select c.CID as CID for json path, without_array_wrapper))) t(j)
group by ID
You can also discover that there are equivalent functions for STRING_AGG and STRING_SPLIT for old versions of SQL servers.