Can we play the lottery and then give the winnings to charity?
Islam exhorts its adherents upon spending in charity. The Almighty says:
O you who believe! Spend of the pure things which you have earned, and of that which we bring forth from the earth for you, and seek not the bad (with intent) to spend thereof (in charity) when you would not take it for yourselves save with disdain; and know that Allah is Absolute, Owner of Praise. [2:267]
The aforementioned verse urges the Muslims to spend in the way of Allah. It also guides them to spend only those things, which they earn not which they get by the game of chance. It enjoins upon them to spend only pure things which implies that what is being spent should be earned lawfully and in case of goods its should not be seconds.
Lotteries etc. we know is not a proper way of earning. It's a kind of gambling and Islam prohibits all kinds of games of chance. Shari`ah has prohibited all kinds of financial transactions in which anyone or more of the parties involved in the transaction gains any amount of money, which it does not morally deserve to gain.
However, there exists another kind of lottery used product promotion. Here you buy a product and sometimes get entitled to win a certain amount or other items of use. This kind of lottery though objectionable morally (as it aims at passing something out in a pleasant package, which might be difficult to sell otherwise,) cannot be objected to on the legal grounds.
In the light of above explanation the answer to your question would be in negative. However, for someone who may have won money through lottery and now they do not want to spend it on themselves, the best way to dispose it would be to give it in charity.