You need to get rid of the .attributes and tell it how to output the generator object
{{state_attr('sensor.grocy_stock', 'products')
| selectattr('name', 'match', 'Bagel')
| list }}
FWIW, if it’s possible that you have items with bagel uncapitalized or somewhere other than the first word of the name field, you should use | selectattr('name', 'match', '.*bagel*.', 'i')