Sure, except that investing in the S&P is just artificially inflating the economy as a whole, whereas my suggestion isn't intended to be "this is my advice for the most profitable use of a government $", it's a suggestion for boosting a small part of the economy to speed up the development / progress of new drugs as a societal benefit.
People who defend the huge profit amounts of pharma companies (which ultimately come from consumers needing healthcare, paying either directly or through insurance) say it's fair because of the huge amount they invest to create the drugs, if the government does most of the investing then they can take most of the profits to subsidise free pills for their population. Seems to me like a more direct benefit (in addition to potential economic benefits of boosting investment levels in a high-exporting industry too) than just the government buying S&P500 index funds.