The commentary in The Five Gospels attributes the creation of this episode to Luke, and also identifies its function in Luke's narrative:
Both the Samaritan and Mary step out of conventional roles in Luke's examples. This is Luke's reason for placing the story of Mary and Martha in tandem with the parable of the Samaritan. The Samaritan for Luke illustrates the second commandment ("Love your neighbor as yourself"), Mary exemplifies the fulfillment of the first commandment ("You are to love the Lord your God with all your heart, with all your soul, with all your energy, and with all your mind").
John P. Meier
Meier [A Marginal Jew III,631] mentions "the hospitable Mary and Martha" as part of a "second group of significant adherents or supporters of Jesus" who did not literally follow him:
... it is not by accident that the hospitable Mary and Martha, the repentant Zacchaeus, and the beloved Lazarus are not called disciples in the Gospels, despite their commitment and service to Jesus. They were among the "stay-at-home" supporters, whose aid to the movement was by no means negligible. By gifts of money, food, and lodging, they supplied Jesus' traveling band of disciples with the necessary support network for a period of over two years. One would like to know whether or to what extent this support system was more than purely accidental and haphazard and may have represented conscious planning on the part of Jesus. In any event, the support system reminds us once again that not all of Jesus' adherents were desperately poor.