There were a number of issues at play that spoke to the cultural, economic, racial, and gender considerations at play between the 1940s - 60s. First, though, the easiest: economic. Put simply, in the American post-WW2 market, westerns, and more broadly, anything to do with the image of the frontier American manly-man, sold well. Coming out of WW2, Americans were hungry for simpler, morally unambiguous entertainment that played up their unique history (quasi-fantasy) of tamers of the wild frontier. Westerns provided this by returning to the tried and true formula of white men taming the lawless and dangerous expanse of the uncivilized "west." I say "returning to" because this was a formula that had been played to death about 100 years earlier in Dime Novels, the cheap pulp literature of the mid-to-late 19th century. Coming out of the very real, horrific realities of WW2, white (male) America was looking for safe, familiar entertainment that put them in the hero's chair, and westerns delivered that. The explosion of the television market offered another avenue through which people could invest in these stories, and along with movies, the western genre experienced a huge boom between 1945-65. Naturally, this only lasted so long, as women, people of color, and other marginalized individuals not heavily represented in the John Wayne western model wanted their own stories. That, and the model was getting old, and like any entertainment fad, studios can only push the same things down audiences throats for so long before they start looking for something new. What really broke the bank, though, was the counter-culture movement that began to take over the public conversation in the mid-1960s.
Westerns transitioned into "dad's entertainment" right around this time, both because it was actually the preferred entertainment of the adult generation of the time, but also because the western stories represented an establishment segment of the entertainment industry. Cowboys weren't dangerous in the same way that 'Cool Hand Luke' or 'Bonnie and Clyde' was. Younger audiences were increasingly rooting against the establishment and for the grey-area-living anti-heroes, and the western trope and character archetypes as presented by the American studio system didn't know how to make that shift (that is, until the 1970s, when they caught on to what Sergio Leone was doing).
In other words, if a person like John Wayne is the face of the classic 50s & 60s western genre, and John Wayne is persecuting blacklisted Hollywood folk and speaking out in favor of the conservative political agenda (as indeed he did), then you're going to lose that juicy 18-34 demographic fast. Indeed, why go out to see the newest western when 'Easy Rider' is playing in the next theater?
So there was a very noticeable social shift in tastes, and almost overnight, the market for westerns evaporated. It didn't help that the classic 50s and 60s western TV and film model didn't feature much in the way of agency for women or people of color, and in the mid-to-late 60s and onward, these same people were beginning to discover that they had access to non-western films catered specifically to them (where they did have agency). Many people point to Cimino's 'Heaven's Gate' as being the end of the western genre in Hollywood, but in truth, it had been dying a slow death for about a decade prior to that.
[Sources; Richard Slotkin, 'Gunfighter Nation'; Michael Denning, 'Mechanic Accents']