Using sed to implement the cp command
filelist="$(
   IFS='
'
   echo "$*" | sed -n '$!H;${x;s/.//;s/\n/ /g;p;}'
   )"

to="$(
   IFS='
'
   echo "$*" | sed '$!d'
   )"


This should do, assuming there are no new lines in the parameter/s.

Your code assume there is only 1 word per argument. This have nearly no impact unless the last argument is a multi word (miss interpreted by your code taking the very last word and not argument).

For this reason:


Use another separator than standard white space/tab for passing the parameter to sed.


Use $* (and not $@) to have the shell separation on argument and not word.
Using IFS Internal Field Separator of the shell.
Using a sub shell to limit IFS scope to this function (hopefully already the case with "$(...)" used for assignation.

Adapt sed to separate argument with new line, and readapt the new line to white space for final value (sed by default work per line so need to load the lines in buffer before working on it at the end).