Butter an 8 x 11-inch baking pan and set aside. Combine lentils and enough cold water to cover in a saucepan. Bring to a boil over high heat. Reduce heat to medium; add butternut squash. Simmer until squash and lentils are tender, about 25 minutes.
Drain. Put chunks of squash in a medium bowl, then mash roughly with a fork or potato masher.
Heat oven to 375°F. In a large bowl, combine lentils, squash, and remaining ingredients except coconut. Spoon mixture into baking dish. Bake 20 minutes. Top with coconut, if using. Let cool 10 minutes before serving.