This is not a problem specific to your script. This is because @onready and _ready() happen before the children are ready themselves. An easy way to solve this is in _process().
var grid_container: GridContainer
func _process():
if grid_container == null and ($Grid/Container).is_node_ready():
grid_container = $Grid/Container