I’m getting a similar error to what has been reported in the past.
I’m using Oxygen 10.2 with Saxon SA-188.8.131.52.
I define a function
<xsl:function name="lib:my_name" as="item()*">
There are <xsl:sequence> elements in “when” clauses in the function body, and an <xsl:if test="exists($data)"> that surrounds the ‘meat’ of the function body.
If the sequence elements are commented out, I don’t get the "The context item is undefined at this point" error message. But when they are uncommented, I get the error message. The “if” may prevent anything at all from being returned, which is what the “item()*” is supposed to allow.