When we say that we leave the beer to mature, at what temperature does that happen and does it need to be carbonated? Can a beer mature in a keg?
Maturation begins the moment fermentation completes, up until it is consumed, therefor no, it does not need to be carbonated. Since maturing the beer is another way of saying "aging the beer", the temperature will vary depending on the current stage it is at.
For instance (assuming an ale yeast strain), once primary fermentation completes and maturing begins, often times people may allow it to age at a slightly warmer temperature than what they fermented it at (e.g. 70°F/21°C or even room temperature). This ensure the yeast is warm enough to clean up after itself. They'll allow it sit at that temperature until they decide to cold crash the beer, at which point they'll try to lower the temperature down to as close to freezing as possible, without actually freezing the beer. After a couple of days/weeks at that temperature, they will allow it to warm for bottling, or move to a keg to force carbonate. For bottling, it's recommended to keep the bottles above 70°F/21°C for two-three weeks to allow for carbonation, and then to cellar at 50°F/10°C, or keg at whichever cold temperature they need to force carbonate (often between 32°F-50°F/0°C-10°C) for a couple of days/weeks, and then keep at serving temperature.
Beer can mature in a keg, but if maturation is a measure of the yeast's ability to impart flavor/aroma characteristics over time, it will occur at a much slower rate. The keg will be most often be stored at serving temperatures, which causes the yeast to go into hibernation/settle out to the bottom of the keg and get pulled out through the tap lines, reducing the amount of yeast left in the keg to mature the beer.
That said, maturation often implies more than just flavor, and includes other characteristics such as appearance/clarity, which will take a variable amount of time depending upon the ingredients used in the recipe and the temperature at which the beer is stored at.