Short answer: This is still debated, but it might be due at least partly to social stereotypes.
Attitudes:
There are many British accents, but the one most likely to be used in comparisons to say, American, Australian, or New Zealand accents is called RP, or the Queen's English. Other accents used include MLE and Estuary, which are more common in modern times. American accents also vary, and the one most commonly used in regional comparisons is called Standard American English, or GenAm, or Network English. Much like RP, the Standard accent is most common in broadcast media.
Subject perceptions of accents are tested using the matched-guise and similar verbal-guise paradigms, in which speakers read the same content in different accents, while listeners, unaware of the manipulation, are asked to rate the speakers on various traits. A common finding in matched-guise research is that people in general prefer standard accents over foreign accents, presumably due to in-group bias. However, can exceptions be made for native speakers of non-standard accents, such as the way Americans rate British accents?
An early study by Stewart, Ryan, & Giles (1985) suggested that Americans indeed perceive British speakers as higher status than own-accent speakers. However, in a later study by Bayard et al (2001), Americans rated the American accent higher than British on many traits, including intelligence and class. Had attitudes changed in the intervening years? Or is the difference due to changes in method used? Results of other studies (eg, Scott, Green, & Rosewarne, 1997; Anderson et al, 2007; Gill, 2009; Wang et al, 2009) also question Americans' preference for the British accent. Even if a preference for the British accent exists among Americans, it may only reflect the RP accent (eg, Trudgill, 1983).
Reasons:
Several hypotheses have been proposed for why listeners might have preferences for some accents over others:
The inherent value hypothesis is favored by many lay people - when asked about their preferences, they often claim that certain accents just "sound better".
The imposed norm hypothesis suggests that certain accents are "standard" in a given culture, and consequently preferred over non-standard accents.
The social connotation hypothesis is a variation that suggests that traits are associated with accents through social stereotypes, influenced by media.
An interesting way to test these hypotheses is to compare listener preferences when they don't recognize the accents that they are asked to rate. To this end, Giles et al (1974) asked Brits to rate Greek accents, and Giles, Bourhis, & Davis (1979) asked Welsh to rate French accents. Native speakers of the rated accents report clear preferences for one accent over another; however in both studies, listeners with no knowledge of the rated languages were unable to discern the accents and gave speakers similar ratings. This result challenges the inherent value hypothesis.
Furthermore, native speaker ratings do not correlate well with how similar accents are to the "standard" accents, challenging the imposed norm hypothesis. A study reported by Trudgill (1983) also demonstrated that native English speakers that can discern British accents give accents different ratings depending on which region or country the listener is from, contrary to both the inherent value and imposed norm hypotheses. Finally, ratings can differ significantly depending on what trait is measured (eg, intelligence, class, solidarity, success). Consequently, the social connotation hypothesis tends to be the dominant theory in current scholarship.
Controversy:
However, while some later studies (eg, Leemanna, Kollyb, & Nolan, 2015) corroborate the social connotation hypothesis, others lend support to the inherent value hypothesis (eg, Ladegaard, 1998; Hiraga, 2005; Gooskens, Hilton, & Schüppert, 2016; Wadas, 2020). It is also possible that accent cannot always reliably be separated from other differences in speech, or that subjects unable to discern accents have nonetheless developed implicit associations through media exposure. Additionally, accent preferences don't always align well with media stereotypes as reported by subjects. More research is needed.
If the social connotation hypothesis is correct, then preference for the British accent may be the result of American Anglophilia - basically, the British have done a good job of branding themselves overseas. Indeed, subjects from many countries (eg, Spain, Norway, Japan) prefer the British accent, but others (eg, Iran, Korea, Denmark, New Zealand, and Australia) seem to prefer the American accent - attributed to Pax Americana, or the USA doing a good job of branding themselves in those countries.