I've found the solution to the problem, it's quite simple. Simply wrap the content in a ContentView.
Thanks Shuowen and Giorgio for your replies. You helped push me towards the final answer :)
<Shell
x:Class="MauiApp2.AppShell"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:MauiApp2"
Shell.FlyoutBehavior="Flyout"
Title="MauiApp2">
<ShellContent
Title="Home"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" />
<Shell.FlyoutContent>
<ContentView>
<Frame BackgroundColor="ForestGreen">
<Label Text="hello"/>
</Frame>
</ContentView>
</Shell.FlyoutContent>
</Shell>