I've never heard of this issue before, so not sure.
You write that it's random. So, there's no pattern at all to it? Does the order on your chart of accounts also change? If you put your P&L side-by side with your chart of accounts, when it's in its 'natural' order, are the accounts in the same order?
To see the current (randomized?) custom order on your chart of accounts, be sure to view it in heretical mode and not sorted by any column:
If you see this little diamond, click it (and then it'll disappear) to return the chart of accounts to its current natural order, and the P&L and Balance Sheet (and other account-based reports) should match that order: