OK, I figured it out after sinking way too much time into this...
tl;dr Fix
Add this to your preamble (after loading linegoal):
\makeatletter
\let\Z@E@linegoal\relax % undefine the property
\zref@newprop*{linegoal}[\linewidth]{\dimexpr
\linewidth -\the\pdflastxpos sp
+\ifodd\c@page
\oddsidemargin
\else\evensidemargin
\fi
+1in+\hoffset
\relax
}% linegoal zref-property
\makeatother
Note that this may lead to an endless loop of changed labels if a page break depends on a \linegoal and the \linegoal itself is moved across pages due to this. In such cases, you may have to adjust the page breaks manually.
Background
Basically, linegoal uses an internal counter \LNGL@unique that is increased by one at every \linegoal occurrence.
The current value of this counter is used to create labels (in the aux file) that look like this:
\zref@newlabel{linegoal/posx.3}{\page{35}\posx{19599809}}
\zref@newlabel{linegoal.3}{\linegoal{\dimexpr \linewidth -19599809sp +\evensidemargin +1in+\hoffset \relax }}
In this example, the value of \LNGL@unique was 3.
The example also already hints at the problem: Page 35 is an odd page, yet we see an \evensidemargin.
However, the linegoal package doesn't just assume \evensidemargin everywhere; it checks whether the page number is even or odd and uses the corresponding margin:
\ifodd\zref@extractdefault{linegoal/posx.\the\LNGL@unique}{page}\c@page
\oddsidemargin
\else\evensidemargin
\fi
... to get the number of the page on which a \linegoal is located, linegoal uses \zref@extractdefault{linegoal/posx.\the\LNGL@unique}{page}\c@page, i.e., if there is a label linegoal/posx.<counter value> in the aux file, then it extracts the page from there, otherwise it use the current page counter value (\c@page).
However, for some reason, the current value of \LNGL@unique is almost always wrong,¹ and hence, the returned page number is wrong (from the second LaTeX run onwards).
¹: You can try for yourself by editing a copy of linegoal.sty and, e.g., replace the code snippet shown above by
\ifodd\zref@extractdefault{linegoal/posx.\the\LNGL@unique}{page}\c@page
\oddsidemargin + \the\LNGL@unique pt
\else\evensidemargin + \the\LNGL@unique pt
\fi
then look at the produced labels in the aux file.
The Fix
Instead of relying on \zref@extractdefault (and thus the apparently wrong \LNGL@unique value), the proposed fix always uses the page counter.
algorithmicenvironments that almost always live on their own page into\parboxes) that wasn't a problem (I have several tens of pages of such algorithms without any issues). I guess I'll have to dig deeper then.... – bitstreichler Feb 09 '24 at 13:16linegoalcreates labels, I can verify the correct selection of odd/evensidemargin by looking at myauxfile after a couple of LaTeX runs and compare the selected offset with the corresponding page reference (due to the high number of such labels in my document, I checked this with a small python script). – bitstreichler Feb 12 '24 at 11:42