I don't know how it got there, but what I do know is that it is going to remain there. Forever and ever and ever until it dies. Or goes out the way it came, but it doesn't look like it's going to do that.
Bugs are irritating like that. "Okay, I'm here, and I'm gonna stay here until I either die, or figure a way out and then come and sting you."
Open the window and let it go.