According to quoteinvestigator.com there is no consensus on who wrote the above saying: Among many guesses include: Edmund Burke, Victor Hugo, George Bernard Shaw, Benjamin Disraeli, and Winston Churchill…
However, it seems likely that Edmund Burke is the author. This is evidenced by an original comment made by a jurist named Anselme Polycarpe Batbie in a book published in 1875 where he attributes the saying to Edmund Burke.
Varied versions of the saying include the following:
If you’re not a socialist before you’re twenty-five, you have no heart; if you are a socialist after twenty-five, you have no head.
If you aren’t a liberal when you’re young, you have no heart, but if you aren’t a middle-aged conservative, you have no head.