I assume when you try to start the engine with the bike on the side stand it is leaning to one side.
When you start it with the stand up I assume you are sitting on the bike and the bike is upright.
Now here is the long shot and not too likely.-------The lean angle sensor.---
BUT with the stand up it starts normally and with the stand down it's difficult to start.------ It REALLY has to be stand related.--( Cause and effect. ) Or something pulling on the wiring near to the stand. Making it connect or dis-connect as it moves.