Is there a theory about investors' behaviour during bubbles? As far as I can see there are two senses in which it's 'rational' for an investor to buy during a bubble. 


The investor has erroneously overvalued the value of the stock/commodity. 
The investor is aware that it's a bubble and is overvalued, but believes he can make a profit by selling before the bubble bursts. 


There are also 'irrational' explanations, such as the investor being caught up in the hype, or fearing missing out. 

The question is, is investor behaviour during bubbles well studied, and are there models explaining it?
The investor has erroneously overvalued the value of the stock/commodity. 

Here is a prominent paper that models irrational bubbles:


  This paper attempts to formalise herd behaviour or mutual mimetic
  contagion in speculative markets. The emergence of bubbles is
  explained as a self-organising process of infection among traders
  leading to equilibrium prices which deviate from fundamental values.
  It is postulated furthermore that the speculators' readiness to follow
  the crowd depends on one basic economic variable, namely actual
  returns. Above average returns are reflected in a generally more
  optimistic attitude that fosters the disposition to overtake others'
  bullish beliefs and vice versa. This economic influence makes bubbles
  transient phenomena and leads to repeated fluctuations around
  fundamental values.


Herd Behaviour, Bubbles and Crashes (Lux (1995))

The investor is aware that it's a bubble and is overvalued, but believes he can make a profit by selling before the bubble bursts. 

Bubbles, rational expectations and financial markets (Blanchard and Watson (1982)) is a famous paper on this subject. 


  This paper investigates the nature and the presence of bubbles in
  financial markets. Are bubbles consistent with rationality? If they
  are, do they, like Ponzi games, require the presence of new players
  forever? Do they imply impossible events in finite time, such as
  negative prices? Do they need to go on forever to be rational? Can
  they have real effects? These are some of the questions asked in the
  first three sections. The general conclusion is that bubbles, in many
  markets, are consistent with rationality, that phenomena such as
  runaway asset prices and market crashes are consistent with rational
  bubbles. In the last two sections, we consider whether the presence of
  bubbles in a particular market can be detected statistically. The task
  is much easier if there are data on both prices and returns. In this
  case, as shown by Shiller and Singleton, the hypothesis of no bubble
  implies restrictions on their joint distribution and can be tested. In
  markets in which returns are difficult to observe, possibly because of
  a nonpecuniary component, such as gold, the task is more difficult. We
  consider the use of both "runs tests" and "tail tests" and conclude
  that they give circumstantial evidence at best.


Here is another:


  We present a model in which an asset bubble can persist despite the
  presence of rational arbitrageurs. The resilience of the bubble stems
  from the inability of arbitrageurs to temporarily coordinate their
  selling strategies. This synchronization problem together with the
  individual incentive to time the market results in the persistence of
  bubbles over a substantial period. Since the derived trading
  equilibrium is unique, our model rationalizes the existence of bubbles
  in a strong sense. The model also provides a natural setting in which
  news events, by enabling synchronization, can have a disproportionate
  impact relative to their intrinsic informational content.


Abreu and Brunnermeier (2003)

[I]s investor behaviour during bubbles well studied, and are there models explaining it? 

Yes, this is a huge literature with probably thousands of papers and hundreds of books written about it. Here is a technical book on the subject:  Asset Pricing under Asymmetric Information: Bubbles, Crashes, Technical Analysis, and Herding,
 These books are more historical than theoretical: Manias, Panics and Crashes: A History of Financial Crises, This Time Is Different: Eight Centuries of Financial Folly, Irrational Exuberance.