According to the documentation of next-auth/react.
getSession is client side method, you are accessing the getSession at the layout file which is not a client side component, hence it is returning null.
In your use-case, you should use getServerSession.