The simple remembrance of his beloved, whomever that may be, changes his state of mind. The speaker is in a profound state of self-loathing. He complains of his own status, ability, situation in life. He is envious of others. This is all very general and subject to any number of interpretations. We don’t know if he is upset because of his lack of wealth, low status, and lack of friends, lost spiritual enlightenment or unrequited love. We just know that he is despondent and completely faults himself. The change in his state of mind comes here:
Yet in these thoughts myself almost despising,
Haply I think on thee, and then my state,
Like to the lark at break of day arising,
From sullen earth, sings hymns at heaven’s gate;
By focusing outwardly on another, he achieves this turn. He changes his state of mind by shifting the focus from himself to others; namely, his beloved. And in the last line, he chooses NOT to change the status that he had bemoaned previously. Again, this status is open to interpretation. The point is that he changed his mental state, so his state in the world (“state with kings”) does not need to change. The ambiguity of “state” helps to underscore the significance of the main theme of the poem. By focusing on others, he is able to be happy.
There have been scholars who claim this is autobiographical. It could be. It also could be applicable to anyone in any situation who is liberated from a lowly state by the thought of another’s love or friendship. There are some religious allusions (hymns, heaven, kings, etc.) which also point to the possibility that this is somewhat inspired by the story of Adam and Eve being outcast from the Garden of Eden. And it could be interpreted as told from either of their perspectives.