If using canned beans, skip to the next step. For dried beans, cook the beans until they are tender but not falling apart. I cooked 1 cup dried navy beans with 3 cups water in the Instant Pot on high pressure for 20 minutes. Strain the beans and reserve the cooking liquid.
Preheat the oven to 325 degrees.
In a Dutch oven or a 10-inch cast-iron skillet, heat the oil over medium-low. Add the onions and garlic with a pinch of salt and the sugar.
Cook the onions over medium heat, stirring frequently, until they have caramelized and are soft and brown.
Stir in the strained beans, sage and rosemary.
Add the molasses, barbecue sauce and mustard to the beans. Mix well.
Add the vegetable stocks or bean cooking liquid to the pot - you need a total of four cups. Mix and bring to a boil. Check seasoning and add salt and pepper as needed.
If using an oven-safe Dutch oven or cast-iron skillet you can transfer the beans to the oven directly. If not, pour the beans and all liquid carefully into a 3-quart baking dish.
Bake the beans, uncovered, for three hours. I like giving the beans a stir a couple of times during the last hour of cooking to make sure everything bakes evenly.