You can silence individual commands inside a function by prepending :silent! just as well, so either :silent! execute or :execute 'silent! %s... would do.
However, you don't need any of this, because :substitute understands a /e flag that suppresses any errors resulting from no pattern matches (cp. :help :s_e).
Also, you only need :execute when you need to interpolate variable contents into a command. Your substitution uses a constant pattern, so you're just making the command more complex (because of the doubling of backslashes) without any benefit:
%s/\s\+$//e
Additional comments on style
- You don't need the
: in :call; this is only needed in (interactive or in a mapping) normal mode to switch to command-line mode. As :autocmd already takes an Ex command, it's superfluous.
- The
== 0 is superfluous as well. 'readonly' is a boolean flag that evaluates to 0 if unset, and 0 evaluates to false in a conditional.
:sflags, see e.g.:help :s_e(BTW: you don't need an:executein your function) – Christian Brabandt Nov 07 '18 at 10:48