this happens OP, but it will fade if you don't fan it.
So when you start thinking about him, stop yourself. Do something else, let it go etc. There are many ways to alter the mind and we aren't a slave to our thoughts - take a google and find something that works for you.
If you are around him, focus on your friend and be detatched from him. It is possible to do this without being rude or obvious.
If your mind goes to him, imagine him doing gross things like picking his toes or nose, or something you personally find really gross - seek the ick. it will come.
As a society we all got caught up for a while that feelings are eveything, but actually feelings are fleeting and you aren't your feelings. Feelings are fickle and feeling change. We should all avoid being ruled by our feelings.
If you actively do this you will find these feelings soon pass, and you will soon be back to normal.
As for why this happens, from my own experience most men (most people even) are at best very average and boring to me, many outright gross, ignorant, sexist, unappealling and I'd much prefer not to be around them. So when I do meet a clever, lovely, attractive man who makes me laugh and gives me attention, who I can spend time with and enjoy their comapny, if they are also physically attractive, well it can be all to easy to get swept up in that - because it is really nice, and it reminds me that I am a hetrosexual woman no matter how unappealling the vast majority of men are to me.
Of course you know that your friend got lucky in love and has made a great match, and this man is 100% not available to you. And lets face it, if he was wanting to betray your good friend and run away with you into an affair or whatever then he would swiftly become very unattractive as you would realise he isn't the man you thought him to be.