You’ve discovered the defining trait of filtered attribute values! When you use a filtered transclusion to define a variable, the variable is set to the value of the first result only.
In case X, since the filter output is a single number, {{{ [<X>] }}} = {{{ [filter<custom>] +[count[]] }}}
In case Y, since the filter output is a list of titles, {{{ [<Y>] }}} ≠ {{{ [filter<custom>] }}}
To save a list of more than one string as a variable, you’ll need to add +[format:titlelist[]join[ ]] to the end of the filter to turn it into a single string (spaces included), e.g.
The “$set with filter param” syntax automatically encloses values that contain spaces inside doubled square brackets (equivalent to the format:titlelist[] operator), and also automatically joins the values into a single space-separated list (equivalent to the join[] operator).
Also note that, while $vars is a valid widget, it has been superseded by the $let widget (introduced in v5.2.1):