In this story, the disciples and Jesus were all sat in someone's house, when a woman comes up with expensive ointment, breaks open its container, and pours it on Jesus. The disciples object, saying it could have been sold and the proceeds given to the poor. Jesus tells them off because it's part of his preparation for being buried. This event is described in Matthew 26:6-13 and Mark 14:3-9 in a similar way, and differently in John 12:1-8. Luke 7:36-50 tells a story with similar features, but so different to the others, that some observers think Jesus was anointed by surprise twice, in different houses. In two of the stories Jesus' head was anointed, in the other two, his feet. In three renditions it occurs in the town of Bethany and four different people are named as the host of the meal. It always ends with Jesus defending the woman against the objections, and praising her for her deeds.
Whose house? Matthew 26:6 and Mark 14:3 both say they were in Simon the Leper's house. This colourfully-named character is not mentioned elsewhere in the Bible, but the assumption is that this is someone who Jesus has healed. In John 12:1 this is explicit, as Lazarus lives there "whom he raised from the dead". In Luke 7:36, it's the house of "one of the Pharisees", linking this event with other stories where Jesus was kind to the Pharisees. Whoever the host, all four renditions have Jesus at the house after being kind towards the household.
Where was the house? Matthew 26:6, Mark 14:3 and John 12:1 all say it was in Bethany. Luke's rather different version has it occur after Jesus brings a buried son back to life in Nain, much further North (Luke 7:11-17); this still fits the theme that the event occurs in a house of someone Jesus has helped.
The ointment. In Matthew 26:7, Mark 14:9 and Luke 7:37, the woman carries an alabaster box of precious ointment. Such boxes were sealed and had to broken open, and then instantly used, which is what the woman does. The version in John 12:3 has her anoint Jesus' feet, not his head, adds that it is precisely one pound of ointment, and also, that she uses her tears and hair to wipe his feet. This very memorable detail isn't noticed by Matthew or Mark. Luke's account also has her anoint his feet (Luke 7:37-38).
The objection. The disciples "indignantly" state that it shouldn't have been wasted, but rather sold and used to help the poor; legitimate and sensible comments, that deserve praise for their egalitarianism. Note that Matthew 26:8 and Mark 14:4-5 say multiple people said the same thing.
John 12:4-6, after adding the other details that no-one else seemed to notice, has just one person object - Judas. And says that actually this wasn't for the good of the poor, but because Judas holds the purse, and would have stolen the money from it. This blunt criticism makes little sense: if the woman's household sold the ointment, then, it would be they who have the money, not Judas. The owner could then give it to the poor - the traditional place to do this was Jerusalem, less than 3km away; even an indirect route would just be an hours' travel there and back. John's version of the event looks like it has been edited once the stories about Judas had become purely negative, and making extra digs by modifying the way the story is told. John as a whole was also written much later than the other gospels.
The rude objection in Luke 7:39 is that the Pharisee didn't like a disreputable woman touching Jesus.
Jesus doesn't seem to understand the basis of their arguments, and says that the disciples are "bothering" the woman. Christians clearly fall on the side of the disciples in this debate, as they have been 'bothering' people to make charitable donations for millennia, and their Church has become very wealthy indeed.
But Jesus has two justifications to excuse his shortness with the disciples.
Many rich folk and wealthy TV evangelists, sitting in mansions adorned with gold, with expensive cars and lifestyles, approve of this reply. Holy people deserve the good stuff! This immoral nonsense supports an entire Christian theology called "the prosperity gospel", designed to convince Christians that God's representatives deserve to keep that which could otherwise be given to the poor. Because... as Jesus says here, there's always more poor people!
Jesus reveals that he is being prepared for burial. This shows Jesus' truly poor communication skills. He could have simply told them from the very beginning - before they went on "bothering" her. No need for the drama or appalling ethics, that inspired much immorality on Earth in the name of the collection on wealth for the godly. All that could have been avoided with a little bit of clear communication.
Also - and as far as Christian theologians say, Jesus already knew this - as Jesus was only dead and buried for a short time, there was no need to anoint the body as it was not going to decay.
The event ends with a prophecy that failed to come true: He says that her story will be told, in memory of her. However, she goes completely unnamed by Matthew; apparently, her name already forgotten.