The function \box_set_to_last:N is essentially the TeX primitive \lastbox and a call such as
\box_set_to_last:N \l_tmpa_box
is the same as
\setbox\l_tmpa_box=\lastbox
Here's what the TeXbook says about it:
The bottom line of the table above refers to \lastbox,
a primitive operation that hasn't been mentioned before. If the last item
on the current horizontal list or vertical list is an hbox or vbox, it
is removed from the list and it becomes the \lastbox; otherwise
\lastbox is void. This operation is allowed in internal vertical
mode, horizontal mode, and restricted horizontal mode, but you cannot use
it to take a box from the current page in vertical mode. In math modes,
\lastbox is always void. At the beginning of a paragraph,
‘{\setbox0=\lastbox}’ removes the indentation box.
So your attempt fails, because the last item in the current horizontal list is a skip.
However, also
a\setbox0=\lastbox\hskip 10pt plus 1fill
will result in \box0 to have zero width; more precisely, it will be void, because the last item isn't an hbox or a vbox, but a character.
You cannot detect the final amount of a skip when a paragraph is being absorbed, because stretching or shrinking happen at a later stage when the paragraph is split into lines.
\hskipinserts a glue, not a box. For more details refer to the TeXbook chapters 11-12. – plante Nov 01 '21 at 14:06