I downloaded a game from my friend's ID and then she told me to logout from her ID
If I do that will I lose the game that I downloaded from her ID?
Logging out of a PSN account and deactivating it are completely different things.
If you log out of your friend's account and log back into yours, you will still be able to play the games linked to her account.
If you delete her account from your PS3, you will not be able to play those games any more.
Yes, as far as I know that's how the PS3's DRM works: You can keep the game on the console as long as at least one owner exists there (and is logged in?). Never tried to share my console or use it with a second account though. If you'd like to keep your own copy independent of your friend, you'll have to buy it yourself.
My friends do this all the time. As long as you are linked to consoles the download is activated and you are able to use it on your console on any account. If you deactivate her account then the data will remain on the console but wont be allowed to access it. Remember you can only have 2 consoles linked on a single PSN account.